feat: 新增实验 7 的第 2 部分

This commit is contained in:
2025-12-18 18:40:15 +08:00
parent f58f9b8519
commit ef11f2aa3a
8 changed files with 48 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
const Koa = require("koa");
const Router = require("@koa/router");
const app = new Koa();
const router = new Router();
app.use(async (ctx, next) => {
ctx.set("Content-type", "application/json")
await next();
})
router.get("/", async (ctx) => {
ctx.body = "Welcome to theKoaServer!";
})
router.get("/about", async (ctx) => {
ctx.body = "This is the about page.";
})
router.get("/contact", (ctx) => {
ctx.body = "This is the contact page."
})
app.use(router.routes()).use(router.allowedMethods());
const port = 3000;
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
})