forked from geesonwong/airbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (53 loc) · 1.59 KB
/
app.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
/**
* Module dependencies.
*/
var path = require('path');
var express = require('express');
var routes = require('./routes');
var config = require('./config').config;
var app = module.exports = express.createServer();
// Configuration
app.configure(function() {
var viewsRoot = path.join(__dirname, 'views');
app.set('views', viewsRoot);
app.set('view engine', 'html');
app.register('.html', require('ejs'));
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({
secret : config.session_secret
}));
app.use(express.methodOverride());
app.use(app.router);
app.use(require('./controllers/account').auth_user);
app.use(express.csrf());
});
var static_dir = path.join(__dirname, 'public');
app.configure('development', function() {
app.use(express.static(static_dir));
app.use(express.errorHandler({ dumpExceptions : true, showStack : true }));
});
app.configure('development_m', function() {
app.use(express.static(static_dir));
app.use(express.errorHandler({ dumpExceptions : true, showStack : true }));
config.port = 5000;
});
app.configure('production', function() {
var maxAge = 3600000 * 24 * 30;
app.use(express.static(static_dir, { maxAge : maxAge }));
app.use(express.errorHandler());
app.set('view cache', true);
});
app.helpers({
config : config
});
app.dynamicHelpers({
csrf : function(req, res) {
return req.session ? req.session._csrf : '';
},
});
// routes
routes(app);
app.listen(config.port, function() {
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});