# koa-vhost

> vhost for koa

Latest version **0.5.0** (published 2014-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-vhost
pnpm add koa-vhost
yarn add koa-vhost
bun add koa-vhost
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.0 |
| Published | 2014-08-15 |
| First published | 2014-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Treri |
| Maintainers | jeremial, treri |
| Keywords | koa, vhost |

## Links

- npm: https://www.npmjs.com/package/koa-vhost
- Repository: https://github.com/Treri/koa-vhost
- Issues: https://github.com/Treri/koa-vhost/issues
- npm.io page: https://npm.io/package/koa-vhost

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^1.0.2
- [jistype](https://npm.io/package/jistype.md) ~0.0.4
- [koa-favi](https://npm.io/package/koa-favi.md) ^0.1.0
- [koa-compose](https://npm.io/package/koa-compose.md) ^2.2.0

## Recent versions

- 0.5.0 (latest) — 2014-08-15
- 0.4.0 — 2014-06-27
- 0.3.0 — 2014-05-23
- 0.2.0 — 2014-05-20
- 0.1.1 — 2014-04-04
- 0.1.0 — 2014-04-03
- 0.0.9 — 2014-03-31
- 0.0.8 — 2014-03-28
- 0.0.7 — 2014-03-28
- 0.0.6 — 2014-03-28
- 0.0.5 — 2014-03-27
- 0.0.4 — 2014-03-27
- 0.0.3 — 2014-03-27
- 0.0.2 — 2014-03-27
- 0.0.1 — 2014-03-27

## README

## koa-vhost

vhost for koajs

### Install

    npm install koa-vhost

### Usage
```js
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

---
_Source: https://npm.io/package/koa-vhost · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
