app.js 808 B

1234567891011121314151617181920212223242526272829303132
  1. const Koa = require('koa');
  2. const bodyParser = require('koa-bodyparser');
  3. const session = require('koa-session-minimal');
  4. const static = require('koa-static');
  5. const path = require('path');
  6. const sys = require('./config/sys.json');
  7. const router = require('./router');
  8. const app = new Koa();
  9. const cookie = {
  10. maxAge: sys.session.max_age,
  11. path: sys.session.path,
  12. domain: sys.session.domain,
  13. httpOnly: sys.session.http_only
  14. }
  15. app.use(bodyParser({
  16. formLimit: '1000000kb',
  17. jsonLimit: '1000000kb'
  18. }));
  19. app.use(session({
  20. key: sys.session.key,
  21. cookie: cookie
  22. }));
  23. app.use(router.routes());
  24. app.use(router.allowedMethods());
  25. app.use(static(path.join(__dirname, sys.static_dir), {handle: true}));
  26. app.listen(sys.port, () => {
  27. console.log(`${sys.pro_name} is starting at port ${sys.port}`);
  28. });