-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (46 loc) · 1.54 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
var config = require("./server/config"),
express = require('express'),
path = require('path'),
logger = require('./server/core/logger')(config.logger),
ejs = require('ejs'),
cookieParser = require('cookie-parser'),
expressLayouts = require("express-ejs-layouts"),
session = require('express-session'),
bodyParser = require('body-parser'),
compression = require("compression"),
app = express(),
route = require("./server/route"),
packageJson = require("./package.json");
app.use(compression());
app.use(cookieParser());
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, '/www/static')));
app.set('views', path.join(__dirname, '/www/view'));
app.set('view engine', 'html');
app.engine('html', ejs.__express);
app.set('layout', 'layout');
//app.use(expressLayouts);
app.disable("x-powered-by");
//启用反向代理
app.enable('trust proxy');
config.version = packageJson.version;
config.name = packageJson.name;
app.locals.config = config;
route(app, config, logger);
if (config.env !== "test") {
app.set('port', process.env.PORT || 8200);
app.listen(app.get('port'), '0.0.0.0', function () {
logger.info('worktile-festival server listening on port %s', app.get('port'));
});
}
if (config.env === 'production') {
process.on("uncaughtException", function (err) {
setTimeout(function () {
process.exit();
}, 1000);
logger.error(err, "process uncaughtException");
});
} else {
app.set('json spaces', 2);
}
module.exports = exports = app;