怎样用原生 Koa 实现路由功能

index.js

const Koa = require("koa");
const app = new Koa();

app.use((ctx) => {
  switch (ctx.url) {
    case "/":
      ctx.body = "<h1>index.html</h1>";
      break;
    default:
      ctx.body = "<h1>404 Not Found.</h1>";
  }
});

app.listen(3000);

posted on 2021-09-09 10:14  aisowe  阅读(28)  评论(0编辑  收藏  举报

导航