app.js
1.08 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
/**
* yoho-activity app
* @author: leo<qi.li@yoho.cn>
* @date: 2017/6/23
*/
'use strict';
const path = require('path');
const utils = require('./utils');
const express = require('express');
const config = require('./config');
const bluebird = require('bluebird');
const ynLib = require('yoho-node-lib');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
let logger;
const app = express();
// 全局注册library
ynLib.global(config);
logger = global.yoho.logger;
global.Promise = bluebird;
global.yoho.utils = utils;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(global.yoho.httpCtx());
app.use((req, res, next) => {
req.user = {}; // 全局的用户数据
next();
});
const middleware = require('./middleware');
try {
// 路由分发
require('./dispatch')(app);
// 错误处理
app.use(middleware.error);
} catch (err) {
logger.error(err);
}
app.listen(config.port, function() {
logger.info('yoho-activity-node started successfully!');
});