const koa = require("koa");
const app = new koa();
app.use(async(ctx) => {
if (ctx.url == "/") {
console.log("这是主页");
ctx.body = "这是主页";
} else if (ctx.url == "/users") {
if (ctx.method == "GET") {
ctx.body = "这是用户列表页";
} else if (ctx.method == "POST") {
ctx.body = "创建用户";
} else {
ctx.status = 405;
}
} else {
ctx.status = 404;
}
})
app.listen(3000, function() {
console.log("请访问127.0.0.1:3000");
})
自己创建koa路由中间件
最新推荐文章于 2023-03-02 09:03:48 发布