Skip to content

Instantly share code, notes, and snippets.

@boutell
Created December 31, 2012 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boutell/4423489 to your computer and use it in GitHub Desktop.
Save boutell/4423489 to your computer and use it in GitHub Desktop.
Nested Express apps. The "Main Wildcard" route always beats all routes in catsApp even though it is added first with app.use. I wish app.use() had the same precedence as adding a route.
// HOPED-FOR BEHAVIOR: /cats says: Cats Home
// ACTUAL BEHAVIOR: /cats says: Main Wildcard
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send('Main Home');
})
var catsApp = express();
catsApp.get('/', function(req, res) {
res.send('Cats Home');
})
app.use('/cats', catsApp);
app.get('/*', function(req, res) {
res.send('Main Wildcard');
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment