index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. const express = require('express');
  2. const session = require('express-session');
  3. const bodyParser = require('body-parser');
  4. const router = require('./router/index');
  5. const config_path = require('./configs/path');
  6. const app = express();
  7. const log = require('./logger').logger('app', 'info');
  8. // app.static(config_path.files);
  9. // app.static(config_path.images);
  10. // app.static(config_path.videos);
  11. app.use(config_path.baseFiles, express.static(config_path.files));
  12. app.use(config_path.baseImages, express.static(config_path.images));
  13. app.use(config_path.baseVideos, express.static(config_path.videos));
  14. app.use(
  15. session({
  16. secret: 'hfy',
  17. name: 'session', //这里的name值得是cookie的name,默认cookie的name是:connect.sid
  18. cookie: { maxAge: 1800000 }, //过期时间半小时
  19. keys: ['owner', 'captcha'], // 用户登陆信息,验证码字段
  20. resave: true,
  21. saveUninitialized: true,
  22. })
  23. );
  24. app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }));
  25. app.use(bodyParser.json({ limit: '10mb' }));
  26. app.use((req, res, next)=>{
  27. log.info(`${req.method} To ${req.url}`);
  28. // 添加时间,用于记录日志
  29. res.queryTime = new Date();
  30. next();
  31. })
  32. app.use('/api',router)
  33. app.get('/hello', (req, res) => {
  34. res.send('合方圆! 成熟可靠!');
  35. });
  36. module.exports = {
  37. path: '/',
  38. handler: app
  39. }