index.js 1.6 KB

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