-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (36 loc) · 1010 Bytes
/
index.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
var express = require("express");
function respondNotFound(req,res){
res.status(404).render('notfound');
}
function staticPage(name,title,path){
return function(req,res){
res.render(name,{path: path, title: title});
};
}
module.exports = function(db){
var sets = db.collection('sets');
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.locals.pretty = true;
app.use(express.bodyParser());
app.get('/',function(req,res){
res.render('index',{path:'/'});
});
app.get('/details/:name',function(req,res){
var name = req.params.name || null;
sets.findOne({slug: name},function(err,doc){
if(err){
res.send(500,err);
} else if (!doc) {
respondNotFound(req,res);
} else {
res.render('details',{doc: doc});
}
});
});
app.get('/about',staticPage('about','About','/about'));
app.use(express.static(__dirname+'/static'));
app.use(respondNotFound);
return app;
};