Skip to content

JiangJie/koa-vhost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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));

About

A vhost middleware for koa application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published