koa-router-plus
v1.0.5
Published
koa router with simple controller
Downloads
1
Readme
koa-router-plus
Create controller and attach related router
Thanks To
Idea comes from koa-router and koa-simple-controller
Installation
Install using npm:
npm install koa-router-plus --save
Usage
index.js
'use strict';
var app = require('koa')();
var router = require('koa-router-plus')();
app.use(router.initialCtrl());
app.use(router.routes());
app.listen(3000);
lib/controller/index.js
module.exports = {
index : function(ctx) {
ctx.body='Welcome to drink bar, What kind of drink do you like?'
},
}
lib/controller/help/coffee.js
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!'
}
}
lib/controller/help/Tea.js
module.exports = {
index : function(ctx) {
ctx.body='Hello, What kind of tea do you like?'
},
hotter: function(ctx) {
ctx.body='Hey, heat it please!'
},
}
Browser
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().
Contribute
You are welcome to contribute.