Skip to content

Serves as a virtual host for servers made with the http module.

Notifications You must be signed in to change notification settings

SeizedBots/node-http-vhost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usage

http-vhost is a lightweight package for managing multiple hosts in the form of http servers.

Installing

Using npm:

npm install http-vhost

Using git:

git clone https://github.com/SeizedBots/node-http-vhost.git

Getting Started

To get started, just instantiate VHost from the package.

const {VHost} = require('http-vhost');

const vhost = new VHost();

//YOUR CODE HERE

Config

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.

About

Serves as a virtual host for servers made with the http module.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published