实验8
This commit is contained in:
23
nodejs/nodeExperiment7/koa-basic-server/index.js
Normal file
23
nodejs/nodeExperiment7/koa-basic-server/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const Koa = require('koa');
|
||||
const { Router } = require('@koa/router');
|
||||
const app = new Koa();
|
||||
const router = new Router();
|
||||
|
||||
router.get('/', async (ctx) => {
|
||||
ctx.body = 'Welcome to the Koa server!';
|
||||
});
|
||||
|
||||
router.get('/about', async (ctx) => {
|
||||
ctx.body = 'This is the about page.';
|
||||
});
|
||||
|
||||
router.get('/contact', async (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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user