-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
54 lines (42 loc) · 1.38 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
/**
* Copyright (c) 2014 Meizu bigertech, All rights reserved.
* http://www.bigertech.com/
* @author JerryC
* @date 14/12/23
* @description
*
*/
var express = require('express'),
bodyParser = require('body-parser'),
http = require('http'),
multer = require('multer'),
path = require("path");
routes = require("./routes");
app = express();
//////////////////////////////////////////////////////////////////
// EXPRESS SETUP
//////////////////////////////////////////////////////////////////
// 设置端口为process.env.PORT或者3000
app.set('port', process.env.PORT || 3000);
// 设置body的解析
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(multer());
// connect内建的中间件,将根目录下的public文件夹设置为存放image、css、js等静态文件的目录
app.use(express.static(path.join(__dirname, 'client')));
var dataProvider = require("./models");
// 初始化模型
module.exports = dataProvider().then(function (models) {
app.models = models;
// 初始化路由
return routes.init(app);
}).then(function (app) {
// 开启服务器
app.listen(app.get('port'),function(err){
if (err){
console.log(err);
}
console.log('Express server listening on port ' + app.get('port'));
});
return app;
});