Skip to content

Instantly share code, notes, and snippets.

@dreamingblackcat
Created July 22, 2015 07:45
Show Gist options
  • Save dreamingblackcat/4477b9695bd0a4f90414 to your computer and use it in GitHub Desktop.
Save dreamingblackcat/4477b9695bd0a4f90414 to your computer and use it in GitHub Desktop.
/**
* Module dependencies.
*/
var express = require('express');
var vhost = require('vhost');
/*
edit /etc/hosts:
127.0.0.1 api.mydomain.local
127.0.0.1 admin.mydomain.local
*/
// Main server app
// require your first app here
var app1 = require("./app1");
// require your second app here
var app2 = require("./app2");
// redirect.use(function(req, res){
// if (!module.parent) console.log(req.vhost);
// res.redirect('http://example.com:3000/' + req.vhost[0]);
// });
// Vhost app
var appWithVhost = module.exports = express();
appWithVhost.use(vhost('admin.mydomain.local', app2)); // Serves top level domain via Main server app
appWithVhost.use(vhost('api.mydomain.local', app1)); // Serves all subdomains via Redirect app
/* istanbul ignore next */
if (!module.parent) {
appWithVhost.listen(8000);
console.log('Express started on port 8000');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment