import Router from '@koa/router'; import { readFile } from 'node:fs/promises'; const router = new Router(); // 定义一个 get的请求方法 路由 // 第一个参数: 路由的路径 // 第二个参数:路由处理的中间件 router .get('/', async (ctx) => { // 需要告诉客户端 你响应的数据类型 // 即需要设置Content-Type响应头 ctx.type = 'text/html;charset=utf8'; ctx.body = await readFile('./pages/index.html'); }) .get('/about', async (ctx) => { ctx.type = 'text/html;charset=utf8'; ctx.body = await readFile('./pages/about.html'); }); export default router;