express-fast-vhosts

Express vhosts system for fast setup

npm install express-fast-vhosts
10 downloads in the last month

Express Fast Vhosts

Example

cat vhosts.json

{
    "vhosts": {
        "myhost": {
            "domain":         "myhost.example.com",
            "controller":     "./path/to/myhost-controller.js"
        },
        "another-host": {
            "domain":         "another-host.example.com",
            "controller":     "./path/to/another-host_controller.js"
        }
    }
}

/etc/hosts

# Express vhosts test
127.0.0.1       myhost.example.com
127.0.0.1       another-host.example.com

app.js

var express   = require('express');
var vhosts    = require('express-fast-vhosts');

var rootApp = express();

vhosts({
    app:           rootApp,
    configPath:    '../../configs/vhosts.json'
});

rootApp.listen(3000);

myhost-controller.js

var index = function(vhost) {
    vhost.get('/', function (req, res) {
        res.send('Good afternoon, gentlemans!');
    });
    vhost.get('/:sub', function (req, res) {
        res.send('requsted ' + req.params.sub);
    });
};


module.exports = index;
npm loves you