-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathroutes.js
124 lines (101 loc) · 2.56 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module.exports = function(app, models, mongoose){
/**
* Index
*/
app.get('/', function(req, res){
if (app.requireAuth === true && req.loggedIn === false)
res.redirect('/auth/twitter');
//get all the examples
models.examples.find({}, function(err, docs){
//render the index page
res.render('index.jade', {
locals: {
title: 'Node.js Express MVR Template',
page: 'index',
examples: docs
}
});
});
});
/**
* Listing
*/
app.get('/list', function(req, res){
if (app.requireAuth === true && req.loggedIn === false)
res.redirect('/auth/twitter');
//get all the examples
models.examples.find({}, function(err, docs){
//render the index page
res.render('list.jade', {
locals: {
title: 'Node.js Express MVR Template',
page: 'list',
examples: docs
}
});
});
});
/**
* View
*/
app.get('/view/:id', function(req, res){
if (app.requireAuth === true && req.loggedIn === false)
res.redirect('/auth/twitter');
//get the example
models.examples.findById(req.params.id, function(err, doc){
//render the view page
res.render('view.jade', {
locals: {
title: 'Node.js Express MVR Template',
page: 'view',
example: doc
}
});
});
});
/**
* Add View
*/
app.get('/add', function(req, res){
if (app.requireAuth === true && req.loggedIn === false)
res.redirect('/auth/twitter');
//render the add page
res.render('add.jade', {
locals: {
title: 'Node.js Express MVR Template',
page: 'add'
}
});
});
/**
* Add test doc
*/
app.post('/posts', function(req, res){
var now = new Date();
var Post = models.examples;
var post = new Post();
post.name = req.param('doc');
post.date = now;
post.save(function(err) {
console.log('error check');
if(err) { throw err; }
console.log('saved');
});
res.redirect('/list');
});
/**
* Add test doc
*/
app.post('/delete', function(req, res){
var id = req.param('id');
models.examples.findById(id, function(err, doc){
doc.remove();
doc.save(function(err){
console.log('error check');
if(err) { throw err; }
console.log('saved');
});
res.redirect('/list');
});
});
};