feat: 新增实验 7 的第 2 部分
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "test7",
|
||||
"name": "7.1",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
30
Server/tests/test7/7.2/index.js
Normal file
30
Server/tests/test7/7.2/index.js
Normal 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}`);
|
||||
})
|
||||
17
Server/tests/test7/7.2/package.json
Normal file
17
Server/tests/test7/7.2/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "7.2",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"packageManager": "pnpm@10.14.0",
|
||||
"dependencies": {
|
||||
"@koa/router": "^15.1.0",
|
||||
"koa": "^3.1.1"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user