index.js
This file
Path
examples/vhost/index.js
46 lines · 890 bytes · JavaScript
Last changed by
Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882
History of this fileTake it
The walk stopped after 200 commits: lines older than 8ac3e80 point at it.
Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 1–6why, one step back1/**2 * Module dependencies.3 */45var express = require('../..');6refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
line 7why, one step back7/*Merge pull request #1598 from colynb/patch-1TJ Holowaychukbefore adoption028d9d8
line 8why, one step back8edit /etc/hosts:Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
line 9why, one step back9refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
lines 10–13why, one step back10127.0.0.1 foo.example.com11127.0.0.1 bar.example.com12127.0.0.1 example.com13*/Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
line 14why, one step back14Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882
line 15why, one step back15// Main server appMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
line 16why, one step back16refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
line 17why, one step back17var main = express();Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
line 18why, one step back18refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
lines 19–22why, one step back19main.use(express.logger('dev'));2021main.get('/', function(req, res){22 res.send('Hello from main app!')Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 23–24why, one step back23});24refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
line 25why, one step back25main.get('/:sub', function(req, res){Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 26–34why, one step back26 res.send('requsted ' + req.params.sub);27});2829// Redirect app3031var redirect = express();3233redirect.all('*', function(req, res){34 console.log(req.subdomains);refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5
line 35why, one step back35 res.redirect('http://example.com:3000/' + req.subdomains[0]);Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 36–37why, one step back36});37Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882
line 38why, one step back38// Vhost appMerge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 39–41why, one step back3940var app = express();41Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882
lines 42–43why, one step back42app.use(express.vhost('*.example.com', redirect)) // Serves all subdomains via Redirect app43app.use(express.vhost('example.com', main)); // Serves top level domain via Main server app Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 44–46why, one step back4445app.listen(3000);46console.log('Express app started on port 3000');