12345678910111213141516171819202122 |
- import Koa from 'koa';
- import serve from 'koa-static';
- import config from './app.config.js';
- import router from './router/index.mjs';
- import { koaBody } from 'koa-body';
- const app = new Koa();
- // 托管静态文件
- app.use(serve(config.public));
- // 一定要在路由之前先处理请求体的转换
- // 默认对 json and xml and urlencoded 进行转换
- app.use(koaBody());
- // 添加路由
- app.use(router.routes());
- // 在options请求下响应支持的请求方法
- app.use(router.allowedMethods());
- app.listen(config.port, config.host, () => {
- console.info(`服务已启动,地址为:'http://${config.host}:${config.port}'.`);
- });
|