Skip to content

nswbmw/koa-version

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-version

Mounting app by version to different router.

Install

npm i koa-version --save

Usage

version(semantic_version, route, app);
  • semantic_version: use semver.
  • route: routing function, app as parameter only.
  • app: koa application.

Example

app.js

var koa = require('koa');
var version = require('koa-version');

var v1Router = require('./v1Router');
var v2Router = require('./v2Router');

var app = koa();

app.use(version('1', v1Router, app));
app.use(version('2', v2Router, app));

app.listen(3000);

v1Router.js

var route = require('koa-route');

module.exports = function (app) {
  app.use(route.get('/hello', function* () {
    this.body = 'v1-hello';
  }));
  app.use(route.get('/world', function* () {
    this.body = 'v1-world';
  }));
};

v2Router.js

var route = require('koa-route');

module.exports = function (app) {
  app.use(route.get('/hello', function* () {
    this.body = 'v2-hello';
  }));
  app.use(route.get('/world', function* () {
    this.body = 'v2-world';
  }));
};

Test

npm test

License

MIT

About

Mounting app by version to different router.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published