1 Star 1 Fork 0

jqClub/blog-node

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.js 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
biaochenxuying 提交于 2018-11-21 21:28 . 提交第一版本
// modules
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const session = require('express-session');
// import 等语法要用到 babel 支持
require('babel-register');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser('blog_node_cookie'));
app.use(
session({
secret: 'blog_node_cookie',
name: 'session_id', //# 在浏览器中生成cookie的名称key,默认是connect.sid
resave: true,
saveUninitialized: true,
cookie: { maxAge: 60 * 1000 * 30, httpOnly: true }, //过期时间
}),
);
const mongodb = require('./core/mongodb');
// data server
mongodb.connect();
//将路由文件引入
const route = require('./routes/index');
//初始化所有路由
route(app);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jqClub/blog-node.git
git@gitee.com:jqClub/blog-node.git
jqClub
blog-node
blog-node
master

搜索帮助