加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
phachon 提交于 2016-12-02 14:55 . 增加about页面
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var bodyParser = require('body-parser');
var config = require('config');
var fs = require('fs');
//加载路由文件
var index = require('./routes/index');
var author = require('./routes/author');
var chat = require('./routes/chat');
var user = require('./routes/user');
var about = require('./routes/about');
var app = express();
//设置 cookie
app.use(cookieParser());
//设置 session
app.use(session({
store: new RedisStore(config.get('redis.session')),
resave:false,
saveUninitialized:false,
secret: 'phachat'
}));
// view engine setup
app.set('views', path.join(__dirname, 'views'));
//app.set('view engine', 'ejs');
// 加载 html 文件
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
//index route
app.use('/', index);
//author route
app.use('/author', author);
//chat route
app.use('/chat', chat);
//user route
app.use('/user', user);
//about route
app.use('/about', about);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
//config path
//var configPath = './config/development';
/**
* development
*/
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
/**
* testing
*/
if (app.get('env') === 'testing') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
/**
* production
*/
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
//config
// var config = require(configPath);
module.exports = app;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化