const Koa = require('koa');
const Router = require('koa-router');
const maty = require('maty');
const app = new Koa();
const router = new Router();
// 挂载maty到某个 路径开头 下
const servePath = '/maty';
const serve = maty();
serve.mount(servePath, app); // ctx.path startsWith /maty
// 屏蔽原服务
app.use(async (ctx, next) => {
if (ctx.path.startsWith(servePath)) {
return;
}
await next();
});
// 原项目服务
router.get('/home', (ctx, next) => {
ctx.body = 'original home page';
});
app
.use(router.routes())
.use(router.allowedMethods());
app.listen(8080);