This repository was archived by the owner on Apr 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (48 loc) · 1.65 KB
/
Copy pathindex.js
File metadata and controls
58 lines (48 loc) · 1.65 KB
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
var path = require('path'),
config = require(path.join(__dirname, 'config')),
ejs = require('ejs-locals'),
express = require('express'),
app = express();
app.configure(function () {
// logging
app.use(express.logger('dev'));
// errorhandling with development info
app.use(express.errorHandler({
dumpExceptions: true,
showStack: true
}));
// add gzip compression
app.use(express.compress());
// allow _PUT, _DELETE, parse form parameters
app.use(express.methodOverride());
app.use(express.bodyParser());
// initialize secret sessions
app.use(express.cookieParser(config.app.secret));
app.use(express.session({
secret: config.app.secret
}));
// use csrf tokens
app.use(express.csrf());
app.use(function (req, res, next) {
res.locals.csrf = req.session._csrf;
next();
});
// set view engine
app.engine('ejs', ejs);
app.set('views', path.join(__dirname, 'themes', config.wiki.theme, 'views'));
app.set('view engine', 'ejs');
// set specific routing
app.use(express.favicon());
app.use(express.static(path.join(__dirname, 'themes', config.wiki.theme, 'public')));
app.use(app.router);
});
// page routes
var routes = require(path.join(__dirname, 'routes', 'articles'));
app.get('/', routes.index);
app.get('/:id', routes.id, routes.view);
app.post('/:id/edit', routes.id, routes.update);
app.post('/:id/delete', routes.id, routes.remove);
// bind app to specific address and port
app.listen(config.app.port, config.app.host, function () {
console.log('listening at http://%s:%s', config.app.host, config.app.port);
});