app.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const Koa = require('koa');
  2. const bodyParser = require('koa-bodyparser');
  3. const session = require('koa-session-minimal');
  4. const MysqlSession = require('koa-mysql-session');
  5. const static = require('koa-static');
  6. const path = require('path');
  7. const sys = require('./config/sys.json');
  8. const router = require('./router');
  9. const app = new Koa();
  10. const store = new MysqlSession({
  11. connectTimeout : 60* 60 * 60 * 1000,
  12. host: sys.session.host,
  13. user: sys.session.user,
  14. password: sys.session.pwd,
  15. database: sys.session.db
  16. });
  17. const cookie = {
  18. maxAge: sys.session.max_age,
  19. path: sys.session.path,
  20. domain: sys.session.domain,
  21. httpOnly: sys.session.http_only
  22. }
  23. app.use(bodyParser({
  24. "formLimit": "50mb",
  25. "jsonLimit": "50mb",
  26. "textLimit": "50mb"
  27. }));
  28. app.use(session({
  29. key: sys.session.key,
  30. store: store,
  31. cookie: cookie
  32. }));
  33. app.use(router.routes());
  34. app.use(router.allowedMethods());
  35. app.use(static(path.join(__dirname, sys.static_dir), {handle: true}));
  36. app.listen(sys.port, () => {
  37. console.log(`${sys.pro_name} is starting at port ${sys.port}`);
  38. });