http-vhost
v1.0.3
Published
Serves as a virtual host for servers made with the http module.
Readme
Usage
http-vhost is a lightweight package for managing multiple hosts in the form of http servers.
Installing
Using npm:
npm install http-vhostUsing git:
git clone https://github.com/SeizedBots/node-http-vhost.gitGetting Started
To get started, just instantiate VHost from the package.
const {VHost} = require('http-vhost');
const vhost = new VHost();
//YOUR CODE HEREConfig
The virtual hosts managed by VHost can be passed in at instantiation. (Listed values are default.)
new VHost({
hosts: [], //these come with a domain and a server property, similar to VHost.register
default: require('http').createServer((req, res) => {
res.writeHead(404, {
'Content-Type': 'text/plain'
});
res.end();
})
});Properties
server
The server property is the http server that wraps the user-provided servers.
vhost.server;Methods
register
This method takes in a domain and a server as created by the http module standard to node. There are several function signatures for this method.
vhost.register('api.example.com', server);Checks for an exact match.
vhost.register(/^\w+\.example\.com$/, server);Checks for a match to the provided regular expression.
vhost.register(server);Is used when no other host can be found.
Access Patterns
The http-vhost module exports the following:
{
VHost: require('./VHost')
}Contributing
If you would like to contribute or create an issue, please do so at the official GitHub page.
