Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created February 7, 2013 11:09
Show Gist options
  • Save geNAZt/4730331 to your computer and use it in GitHub Desktop.
Save geNAZt/4730331 to your computer and use it in GitHub Desktop.
var express = require('express'),
vm = require('vm'),
app = express(),
vhosts = {
"www.house-of-code.org": vm.createContext({app: app, require: require}),
"test.house-of-code.org": vm.createContext({app: app, require: require})
};
var vhostWWW = vm.createScript("var express = require('express')," +
" vhostApp = express();" +
"vhostApp.get('/', function(req, res) {" +
" res.end('WWW');" +
"});" +
"app.use(express.vhost('www.house-of-code.org', vhostApp));");
vhostWWW.runInContext(vhosts["www.house-of-code.org"]);
var vhostTest = vm.createScript("var express = require('express')," +
" vhostApp = express();" +
"vhostApp.get('/', function(req, res) {" +
" res.end('test'); throw new Error('test');" +
"});" +
"app.use(express.vhost('test.house-of-code.org', vhostApp));");
vhostTest.runInContext(vhosts["test.house-of-code.org"]);
app.listen(8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment