Created
April 6, 2011 17:38
-
-
Save williscool/906110 to your computer and use it in GitHub Desktop.
Testing out a vhost setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Expose modules in ./support for demo purposes | |
/** | |
* Module dependencies. | |
*/ | |
var express = require('express'); | |
// Edit /etc/vhosts | |
// First app | |
var one = express.createServer(); | |
one.use(express.logger()); | |
one.get('/', function(req, res){ | |
res.send('Hello from app one!') | |
}); | |
one.get('/:sub', function(req, res){ | |
res.send('requsted ' + req.params.sub); | |
}); | |
// App two | |
var two = express.createServer(); | |
two.get('/', function(req, res){ | |
res.send('Hello from app two!') | |
}); | |
// Redirect app | |
var redirect = express.createServer(); | |
redirect.all('*', function(req, res){ | |
console.log(req.subdomains); | |
res.redirect('http://localhost:3000/' + req.subdomains[0]); | |
}); | |
// Main app | |
var app = express.createServer(); | |
app.use(express.vhost('*.localhost', redirect)) | |
app.use(express.vhost('localhost', one)); | |
app.use(express.vhost('dev', two)); | |
app.use(express.logger()); | |
app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); | |
app.all('*', function(req, res){ | |
console.log(req.headers.host); | |
}); | |
app.listen(80); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment