vhost-koa
v0.0.3
Published
A koa middleware for koa appication.
Downloads
2
Readme
koa-vhost
A vhost middleware for koa application.
Forked from koa-vhost
Install
npm i vhost-koa --save
or install from github
npm i JiangJie/koa-vhost --save
Example
let koa = require('koa');
let mount = require('koa-mount');
let Router = require('koa-router');
let vhost = require('vhost-koa');
let app = koa();
let vhosts = ['127.0.0.1', 'localhost'];
vhosts = vhosts.map(function(item) {
try {
let vapp = koa();
let API = new Router();
API.get('/', function*() {this.body = 'hello';});
vapp.use(mount('/', API.middleware()));
return {
host: item,
app: vapp
};
} catch(e) {
console.log('vhost error %s', e.message);
return;
}
}).filter(function(item) {
return !!item;
});
app.use(vhost(vhosts));