| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- const express = require('express');
- const session = require('express-session');
- const bodyParser = require('body-parser');
- const router = require('./router/index');
- const config_path = require('../configs/path.json');
- const path = require("path");
- const app = express();
- const log = require('./logger').logger('app', 'info');
- // app.static(config_path.files);
- // app.static(config_path.images);
- // app.static(config_path.videos);
- app.use(config_path.baseFiles, express.static(config_path.files));
- app.use(config_path.baseImages, express.static(config_path.images));
- app.use(config_path.baseVideos, express.static(config_path.videos));
- app.use('/public' + config_path.baseFiles, express.static(config_path.files));
- app.use('/public' + config_path.baseImages, express.static(config_path.images));
- app.use('/public' + config_path.baseVideos, express.static(config_path.videos));
- app.use(
- session({
- secret: 'hfy',
- name: 'session', //这里的name值得是cookie的name,默认cookie的name是:connect.sid
- cookie: { maxAge: 2800000 }, //过期时间半小时
- keys: ['owner', 'captcha'], // 用户登陆信息,验证码字段
- resave: true,
- saveUninitialized: true,
- })
- );
- app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));
- app.use(bodyParser.json({ limit: '10mb' }));
- app.use((req, res, next)=>{
- log.info(`${req.method} To ${req.url}`);
- // 添加时间,用于记录日志
- res.queryTime = new Date();
- next();
- })
- app.use('/api',router)
- app.get('/hello', (req, res) => {
- res.send('合方圆! 成熟可靠!');
- });
- module.exports = {
- path: '/',
- handler: app
- }
|