create a demo with koa, typescript, bootstrap
yarn install
yarn start
After that
Go to debug pannel and open launch.json
, in the configurations
section, create the debug data as follow:
{
"type": "node",
"request": "launch",
"name": "KOA debug",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ts-node-dev",
"args": [
"${workspaceFolder}/server.ts"
],
"restart": true
}
This demo uses the art-template for the view engine
-
Create seperated controller in Controller folder and add the static action for each router request.
export default class HomeController { public static async getHome(ctx: any) { await ctx.render('index'); } }
-
Create routers file and import the controller action
const routers = [ { path: '/', method: 'get', action: HomeController.getHome } ];
-
Apply the routers to App
const router = Router(); routers.forEach(r => router[r.method](r.path, r.action)); app.use(router.routes()); app.use(router.allowedMethods());