Thunderflurry Virtual Host
Middleware for express
or connect
to create virtual, self-contained application nodes in ThunderFlurry. Based originally on virtual-host, overhauled to add features specifically needed for ThunderFlurry's core.
Install
$ npm install thunderflurry-virtualhost --save
Requre
var host = express;
Or ES7
import virtualhost from 'thunderflurry-virtualhost';
const host = virtualhost(express);
API
vhost(hostname)
Creates an instance of express
(or connect
), and a middleware you can .use
in your main application.
You must provide a hostname
to 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-zA-Z_0-9.*-]
. You may also provide an array of hostnames to hostname
.
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
Special case: The tile ~
is a special case that will match localhost and the root domain. Example:
// matches localhost and example.com // matches localhost and example.com and www.example.com
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;
vhost(hostname).handlesRoot
Returns true if ~
was used as a hostname and false if it wasn't included.
Usage
var express = ;var vhost = express;var app = ;var www = ; if wwwhandlesRoot console;
vhost(hostname).hosts
Returns the array of hosts the adapter is handling.
Usage
var express = ;var vhost = express;var app = ;var www = ; www