app.js
This file
Path
examples/vhost/app.js
53 lines · 989 bytes · JavaScript
Last changed by
Added vhost exampleTj Holowaychukbefore adoption9e9c3ee
History of this fileTake it
Added vhost exampleTj Holowaychukbefore adoption9e9c3ee
lines 1–53why, one step back12// Expose modules in ./support for demo purposes3require.paths.unshift(__dirname + '/../../support');45/**6 * Module dependencies.7 */89var express = require('../../lib/express');1011// Edit /etc/vhosts1213// First app1415var one = express.createServer();1617one.use(express.logger());1819one.get('/', function(req, res){20 res.send('Hello from app one!')21});2223one.get('/:sub', function(req, res){24 res.send('requsted ' + req.params.sub);25});2627// App two2829var two = express.createServer();3031two.get('/', function(req, res){32 res.send('Hello from app two!')33});3435// Redirect app3637var redirect = express.createServer();3839redirect.all('*', function(req, res){40 console.log(req.subdomains);41 res.redirect('http://localhost:3000/' + req.subdomains[0]);42});4344// Main app4546var app = express.createServer();4748app.use(express.vhost('*.localhost', redirect))49app.use(express.vhost('localhost', one));50app.use(express.vhost('dev', two));5152app.listen(3000);53console.log('Express app started on port 3000');