app.js 1.1 KB

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