Create controller and attach related router
Idea comes from koa-router and koa-simple-controller
Install using npm:
npm install koa-router-plus --save
'use strict';
var app = require('koa')();
var router = require('koa-router-plus')();
app.use(router.initialCtrl());
app.use(router.routes());
app.listen(3000);
module.exports = {
index : function(ctx) {
ctx.body='Welcome to drink bar, What kind of drink do you like?'
},
}
module.exports = {
index : function(ctx) {
ctx.body='Hello, What kind of coffee do you like?'
},
moreSugar: function(ctx) {
ctx.body='Sugar, please!'
},
moreMilk: function(ctx) {
ctx.body='Milk, please!'
}
}
module.exports = {
index : function(ctx) {
ctx.body='Hello, What kind of tea do you like?'
},
hotter: function(ctx) {
ctx.body='Hey, heat it please!'
},
}
URL: http://localhost:3000/, Means call index.index().
URL: http://localhost:3000/help/coffee, Means call help.coffee.index().
URL: http://localhost:3000/help/coffee/moreSugar, Means call help.coffee.moreSugar().
You are welcome to contribute.