8000 GitHub - shifuture/koa-router-plus: koa router with simple controller
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

shifuture/koa-router-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

License

MIT

About

koa router with simple controller

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0