-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.js
58 lines (52 loc) · 1.53 KB
/
start.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
require('./core');
const express = require('nanoexpress');
const bodyParser = require('@nanoexpress/middleware-body-parser/cjs');
const session = require('express-session');
const app = express();
app.use(bodyParser());
app.use(session({
secret: '12345',
cookie: {
secure:true,
maxAge: 10000 },
saveUninitialized: true,
resave: false,
}));
app.use( function(req, res, next) {
res.callback = (code, msg, data) => {
let result = {};
if (msg == null&& data==null
&& (typeof code === 'object')){
if (code && code.hasOwnProperty('code')){
result = code;
} else {
result = {'code': 0, 'msg': '', 'data': code};
}
} else {
result = {'code': code || 0, 'msg': msg || '', 'data': data == null?{}:data};
}
if (process.env.NODE_ENV === 'test'){
result['params']=req.params;
}
res.json(result);
};
let cookies = req.headers['cookie'] || req.headers['Cookie'];
cookies = String.map(cookies, ';', '=');
req.DEVICE = cookies;
if (next){
next();
}
});
const Controller = require('./controller');
new Controller(app).init();
process.setMaxListeners(0);
app.listen(CONFIG.server.port).then(()=>{
let message =
`--------------------------------
HTTP Server listening
${CONFIG.server.name}
on port ${CONFIG.server.port}
on debug ${CONFIG.server.debug}
--------------------------------`;
console.log(message);
});