An mounting middleware for koa
siren-mount is modified from the koa-mount by:
- Support for express path using path-to-regexp.
npm install --save siren-mount
The usage is the same as koa-mount, except:
You can use regular expression as prefix:
var app = koa();
var router = koa();
app.use(mount(/\/([^\/]+)\/?/i, function *() {
// Matches /abc, /abc/, /abcdadc/dsd
}));
You can use ctx.params
to access the URL parameters:
var app = koa();
var router = koa();
app.use('/:id', function *() {
console.log(this.params.id);
}));
MIT