-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
63 lines (49 loc) · 1.61 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
var express = require('express');
var http = require('http');
var app = express();
var config = require('./config')(app.settings.env);
var server = http.createServer(app);
var io = require('socket.io').listen(server);
var lessMiddleware = require('less-middleware')(config.lessMiddleware);
var expressLayouts = require('express-ejs-layouts');
var setupHandlers = require('./handlers.js');
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set("layout extractScripts", true);
app.set("io", io);
app.set("config", config);
app.use(express.favicon('public/icon.ico'))
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.compress())
app.use(lessMiddleware);
app.use(express.static('public'));
app.use(express.cookieParser());
app.use(function(req, res, next) {
if (!req.cookies.id) {
var id = require('identifier')(20);
res.cookie('id', id, { maxAge: 1000 * 60 * 60 * 24 * 365 * 10 })
req.cookies.id = id;
}
next();
});
app.use(expressLayouts);
app.use(app.router);
app.use(function(req, res){
res.render('404.html.ejs');
});
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
require('console-trace');
console.traceAlways = true;
});
app.configure('production', 'stage', function(){
app.use(express.errorHandler());
});
setupHandlers(app);
app.locals.env = app.settings.env;
var port = 3333;
server.listen(port);
console.log("Express server listening on port %d in %s mode", port, app.settings.env);