1.8.1 oak如何跟koa2中路由分割

我想跟koa2中路由分割一样。
访问这个:localhost:8080/hall/get

import { Application } from “https://deno.land/x/oak/mod.ts”;

import { Router } from “https://deno.land/x/oak/mod.ts”;

const app = new Application();

const hall = new Router();

const getProducts = ({ response }: { response: any }) => {

response.body = {

  success: true,

  data: 'getProducts',

};

};

hall.get("/get", getProducts);

const router = new Router();

router.use(’/hall’,hall.routes(),hall.allowedMethods());

app.use(router.routes());

app.use(router.allowedMethods());

await app.listen({ port: 8080 });

1赞

后面采用廖雪峰老师的方法。
自动扫描controllers 目录,找到所有js 文件,导入,然后注册每个URL: