1 Star 0 Fork 5

黑夜的太阳/NodeExpressAdmin

forked from ciey/NodeExpressAdmin 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 2.13 KB
一键复制 编辑 原始数据 按行查看 历史
ciey 提交于 2019-08-27 13:51 . Initial commit
/****************************************************************************************
* app.js
* Node.js >= 8.0.0
* database : mysql, redis
* server : ubuntu 16.04 / nginx
***************************************************************************************/
'use strict';
const _ = require('lodash');
const path = require('path');
const config = require('./config');
const express = require('express');
require('express-async-errors');
const session = require('express-session');
const redisStore = require('connect-redis')(session);
const cookieParser = require('cookie-parser');
const compression = require('compression');
const bodyParser = require('body-parser');
const moment = require('moment');
const logger = require('./common/logger');
const requestLog = require('./middleware/requestLog');
const router = require('./router');
const app = express();
// view engine setup
app.engine('ejs', require('ejs-mate'));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// server static files
app.use('/assets', express.static(path.join(__dirname, 'assets')));
app.use('/upload/public', express.static(path.join(__dirname, 'upload/public')));
// log4js
app.use(require('log4js').connectLogger(logger, { level: config.debug ? 'DEBUG' : 'ERROR' }));
// Request logger
app.use(requestLog);
// parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(compression());
// session support redis store
app.use(session({
store: new redisStore(config.redis),
resave: true,
saveUninitialized: false,
secret: config.session_secret
}));
// locals
app.use((req, res, next) => {
res.locals.user = req.session.user;
res.locals.moment = moment;
res.locals.site = config.site;
next();
});
// routes
app.use('/', router);
// error handle
app.use((err, req, res, next) => {
logger.error(err.message, err);
if (req.xhr) {
return res.json({
state: false,
msg: err.message
});
}
//return res.send(err.message);
next(err);
});
app.listen(config.port,() => {
logger.info('server listening on port:' + config.port);
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/bianbianer/NodeExpressAdmin.git
git@gitee.com:bianbianer/NodeExpressAdmin.git
bianbianer
NodeExpressAdmin
NodeExpressAdmin
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385