virtual-host
Create virtual, self-contained connect
or express
applications using a very simple API.
Install
Use npm
$ npm install virtual-host --save
Require
var vhost = express;
You can also require
it with connect
, if you are not using express
.
API
#vhost(hostname)
Creates an instance of express
(or connect
), and a middleware you can .use
in your main application.
You can provide a hostname
, which defaults to '*'
, to further restrict the hostnames the virtual server will be used on. hostname
is used to build a regular expression to test against req.headers.host
, after stripping out the port
. Stars '*'
will be converted to (.*)
. You can use any characters in this set: [A-z_0-9.*-]
.
You can also just use a RegExp
object as a hostname
directly.
Example hostnames:
// results in /^(.*)$/ // results in /^(.*)\.foo\.com$/i // results in /^www\.(.*)\.com$/i // results in /^www\.foo\.com$/i
#vhost(hostname).off
Turns off the middleware, it will automatically .next
all future requests.
var express = ;var vhost = express;var www = ; // configure www app; ;
#vhost(hostname).on
Turns on the middleware, it will start handling requests once again.
var express = ;var vhost = express;var www = ; // configure www app; ;
#vhost(hostname).server
Exposes the express
or connect
instance used by this vhost
.
Usage
var express = ;var vhost = express;var app = ;var www = ; www; app;