Comparing version 3.0.0 to 3.0.1
@@ -0,1 +1,6 @@ | ||
3.0.1 / 2015-07-19 | ||
================== | ||
* perf: enable strict mode | ||
3.0.0 / 2014-08-29 | ||
@@ -2,0 +7,0 @@ ================== |
12
index.js
@@ -8,2 +8,4 @@ /*! | ||
'use strict' | ||
/** | ||
@@ -15,3 +17,3 @@ * Create a vhost middleware. | ||
* @return {Function} | ||
* @api public | ||
* @public | ||
*/ | ||
@@ -55,3 +57,3 @@ | ||
* @return {string} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -81,3 +83,3 @@ | ||
* @return {boolean} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -93,3 +95,3 @@ | ||
* @param (string|RegExp} val | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -123,3 +125,3 @@ | ||
* @return {object} | ||
* @api private | ||
* @private | ||
*/ | ||
@@ -126,0 +128,0 @@ |
{ | ||
"name": "vhost", | ||
"description": "virtual domain hosting", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
@@ -12,6 +12,5 @@ "contributors": [ | ||
"devDependencies": { | ||
"istanbul": "0.3.0", | ||
"mocha": "~1.21.4", | ||
"should": "~4.0.1", | ||
"supertest": "~0.13.0" | ||
"istanbul": "0.3.17", | ||
"mocha": "2.2.5", | ||
"supertest": "1.0.1" | ||
}, | ||
@@ -18,0 +17,0 @@ "files": [ |
@@ -21,6 +21,7 @@ # vhost | ||
### vhost(hostname, server) | ||
### vhost(hostname, handle) | ||
Create a new middleware function to hand off request to `server` when the incoming | ||
host for the request matches `hostname`. | ||
Create a new middleware function to hand off request to `handle` when the incoming | ||
host for the request matches `hostname`. The function is called as | ||
`handle(req, res, next)`, like a standard middleware. | ||
@@ -116,2 +117,33 @@ `hostname` can be a string or a RegExp object. When `hostname` is a string it can | ||
### using with any generic request handler | ||
```js | ||
var connect = require('connect') | ||
var http = require('http') | ||
var vhost = require('vhost') | ||
// create main app | ||
var app = connect() | ||
app.use(vhost('mail.example.com', function (req, res) { | ||
// handle req + res belonging to mail.example.com | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.end('hello from mail!') | ||
})) | ||
// an external api server in any framework | ||
var httpServer = http.createServer(function (req, res) { | ||
res.setHeader('Content-Type', 'text/plain') | ||
res.end('hello from the api!') | ||
}) | ||
app.use(vhost('api.example.com', function (req, res) { | ||
// handle req + res belonging to api.example.com | ||
// pass the request to a standard Node.js HTTP server | ||
httpServer.emit('request', req, res) | ||
})) | ||
app.listen(3000) | ||
``` | ||
## License | ||
@@ -121,11 +153,11 @@ | ||
[npm-image]: https://img.shields.io/npm/v/vhost.svg?style=flat | ||
[npm-image]: https://img.shields.io/npm/v/vhost.svg | ||
[npm-url]: https://npmjs.org/package/vhost | ||
[travis-image]: https://img.shields.io/travis/expressjs/vhost.svg?style=flat | ||
[travis-image]: https://img.shields.io/travis/expressjs/vhost/master.svg | ||
[travis-url]: https://travis-ci.org/expressjs/vhost | ||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/vhost.svg?style=flat | ||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/vhost/master.svg | ||
[coveralls-url]: https://coveralls.io/r/expressjs/vhost | ||
[downloads-image]: https://img.shields.io/npm/dm/vhost.svg?style=flat | ||
[downloads-image]: https://img.shields.io/npm/dm/vhost.svg | ||
[downloads-url]: https://npmjs.org/package/vhost | ||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat | ||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg | ||
[gratipay-url]: https://gratipay.com/dougwilson/ |
9444
3
117
161