1.配置路由 app.jsjavascript
// 引入模塊 const Koa = require('koa'); const router = require('koa-router')(); /*引入是實例化路由 推薦*/ // 實例化 let app = new Koa(); router.get('/', async (ctx) => { ctx.body = '首頁'; }) router.get('/news', async (ctx) => { ctx.body = '新聞列表頁面'; }) router.get('/newscontent', async (ctx) => { ctx.body = '新聞詳情'; }) app.use(router.routes()); app.use(router.allowedMethods()); app.listen(3000);
.java