-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (36 loc) · 1.3 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
var express = require('express');
var app = express();
var http = require('http');
var server = http.createServer(app);
var engine = require('ejs-locals');
var development = require('./config/environments/development');
var production = require('./config/environments/production');
var routes = require('./routes.js');
app.set('ipaddr', '127.0.0.1');
app.set('port', 8888);
app.engine('ejs', engine);
app.set('view engine', 'ejs');
// app.enable('trust proxy'); // trust X-Forwarded-* when behind nginx
app.enable('strict routing');
app.use(express.bodyParser());
app.use(express.methodOverride());
if (app.get('env') === 'production') {
production.init(app);
} else {
development.init(app);
app.use(function (req, res, next) { development.refresh(req, res, next, app); });
}
routes.route(app);
// TODO: add request logging
// if path/ falls through, remove mistaken trailing slash
app.use(function (req, res, next) {
if (req.path.substr(-1) === '/' && req.path.length > 1) {
var query = req.url.slice(req.path.length);
res.redirect(301, req.path.slice(0, -1) + query);
} else {
next();
}
});
server.listen(app.get('port'), app.get('ipaddr'), function () {
console.log('Serving ' + app.get('ipaddr') + ':' + app.get('port') + ' in ' + app.get('env') + ' mode');
});