-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
73 lines (61 loc) · 1.74 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
66
67
68
69
70
71
72
73
/*
* Module dependencies.
*/
'use strict';
var express = require('express');
var http = require('http');
var path = require('path');
var routes = require('./routes');
var config = require('./config').config;
var i18n = require('./config').i18n;
var flash = require('connect-flash');
var app = express();
var view_path = __dirname + '/views';
var favicon_path = __dirname + '/public/images/ico/united.png';
var static_path = __dirname + '/public';
// all environments
app.set('port', config.port);
app.engine('.html', require('ejs').__express);
app.set('views', view_path);
app.set('view engine', 'html');
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({
secret: config.session_secret,
cookie: {
maxAge: 60 * 60000
}
}));
app.use(flash());
app.use(i18n.init);
app.locals.title = config.title;
app.locals.brand = config.title;
app.locals.timeFormat1 = config.timeFormat1;
app.locals.weibo = config.weibo;
app.use(function(req, res, next) {
res.locals.i18nlocale = req.cookies.i18nlocale;
res.locals.session = req.session;
res.locals.moment = require('moment');
res.locals.moment.lang(res.locals.i18nlocale);
next();
});
//app.use(express.favicon(favicon_path));
app.use('/resources', express.static(static_path));
app.set('env', 'development');
// development only
if ('development' === app.get('env')) {
app.use(express.errorHandler());
app.use(express.logger('dev'));
}
//production only
if ('production' === app.get('env')) {
app.use(express.logger());
db(config.db.mongo);
}
app.use(app.router);
routes(app);
http.createServer(app).listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});