app.js
1.24 KB
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
/**
* app.js
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/04/13
*/
'use strict';
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const Express = require('express');
const session = require('express-session');
const config = require('./common/config');
const logger = require('yoho-node-lib/lib/logger').init(config);
const helpers = require('yoho-node-lib/lib/helpers');
let app = new Express();
global.yoho = {
logger,
helpers,
config,
apiDomain: config.apiDomain
};
app.use(session({
secret: 'yoho!shop@manage',
resave: false,
saveUninitialized: true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
const middleware = require('./middleware');
const controllers = require('./controllers');
try {
// 前置中间件
app.use(middleware.before);
// controller
app.use(controllers);
// // 鉴权中间件
app.use(middleware.auth);
// // 后置中间件
app.use(middleware.proxy);
// // 异常捕获中间件
app.use(middleware.error);
} catch (err) {
logger.error(err);
}
app.listen(config.port, () => {
logger.info(`yoho shop manage start at ${config.port}`);
});