index.js 477 B

1234567891011121314151617
  1. import Koa from 'koa';
  2. import serve from 'koa-static';
  3. import config from './app.config.js';
  4. import router from './router/index.mjs';
  5. const app = new Koa();
  6. // 托管静态文件
  7. app.use(serve(config.public));
  8. // 添加路由
  9. app.use(router.routes());
  10. // 在options请求下响应支持的请求方法
  11. app.use(router.allowedMethods());
  12. app.listen(config.port, config.host, () => {
  13. console.info(`服务已启动,地址为:'http://${config.host}:${config.port}'.`);
  14. });