Skip to content
Myr

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 file

Take 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 back
1/**
2 * Module dependencies.3 */45var express = require('../..');6

refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5

line 7why, one step back
7/*

Merge pull request #1598 from colynb/patch-1TJ Holowaychukbefore adoption028d9d8

line 8why, one step back
8edit /etc/hosts:

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

line 9why, one step back
9

refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5

lines 10–13why, one step back
10127.0.0.1 foo.example.com
11127.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 back
14

Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882

line 15why, one step back
15// Main server app

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

line 16why, one step back
16

refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5

line 17why, one step back
17var main = express();

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

line 18why, one step back
18

refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5

lines 19–22why, one step back
19main.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 back
23});
24

refactor vhost exampleTJ Holowaychukbefore adoptionbb29da5

line 25why, one step back
25main.get('/:sub', function(req, res){

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

lines 26–34why, one step back
26 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 back
35 res.redirect('http://example.com:3000/' + req.subdomains[0]);

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

lines 36–37why, one step back
36});
37

Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882

line 38why, one step back
38// Vhost app

Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80

lines 39–41why, one step back
39
40var app = express();41

Merge pull request #1634 from joshlangner/patch-1TJ Holowaychukbefore adoptione59a882

lines 42–43why, one step back
42app.use(express.vhost('*.example.com', redirect)) // Serves all subdomains via Redirect app
43app.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 back
44
45app.listen(3000);46console.log('Express app started on port 3000');