• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

wyntau/koa-vhost: vhost for koajs

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

wyntau/koa-vhost

开源软件地址:

https://github.com/wyntau/koa-vhost

开源编程语言:

JavaScript 100.0%

开源软件介绍:

koa-vhost

vhost for koajs

Install

npm install koa-vhost

Usage

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

var server = koa();
var server1 = koa();
var server2 = koa();
var server3 = koa();
var server4 = koa();
var server5 = koa();

server1.use(function *(next) {
    this.body = 'server1';
});

server2.use(function *(next) {
    this.body = 'server2';
});

server3.use(function *(next) {
    this.body = 'server3';
});

server4.use(function *(next) {
    this.body = 'server4';
});

server5.use(function *(next) {
    this.body = 'server5';
});

server.use(vhost('s1.example.com', server1));

server.use(vhost(/s2\.example\.com/, server2));

server.use(vhost({
    host: 's3.example.com',
    app: server3
}));

server.use(vhost([{
    host: 's4.example.com',
    app: server4
}, {
    host: /s5\.example\.com/,
    app: server5
}]));

server.use(function * (next) {
    this.body = 'default server';
});

server.listen(3000, function() {
    console.log('server listening port 3000');
});

Then write to your /etc/hosts

127.0.0.1 example.com
127.0.0.1 s1.example.com
127.0.0.1 s2.example.com
127.0.0.1 s3.example.com
127.0.0.1 s4.example.com
127.0.0.1 s5.example.com

Then

request s1.example.com:3000 will return server1;

request s2.example.com:3000 will return server2;

request s3.example.com:3000 will return server3;

request s4.example.com:3000 will return server4;

request s5.example.com:3000 will return server5;

request example.com:3000 will return default server;

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap