forked from welkinwong/nodercms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (41 loc) · 1.06 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
var path = require('path');
var _ = require('lodash');
var express = require('express');
var compression = require('compression');
var favicon = require('serve-favicon');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var validator = require('./lib/validator.lib');
var session = require('./lib/session.lib');
var logger = require('./lib/logger.lib');
var router = require('./lib/route-map.lib');
var errors = require('./core/controllers/errors.controller').error;
var app = express();
/**
* 设置模板解析
*/
app.set('view engine', '.hbs');
/**
* 中间件
*/
app.use(compression());
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger.access());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(validator());
app.use(cookieParser());
app.use(session.check(), session.init());
app.use(express.static(path.join(__dirname, 'public')));
/**
* 转给 Roter 处理路由
*/
app.use(router);
/**
* 错误处理程序
*/
app.use(errors);
/**
* 导出 APP
*/
module.exports = app;