From f4052e5bb0983d637d1a267e121107807f829617 Mon Sep 17 00:00:00 2001 From: jkaplon Date: Wed, 29 Jun 2016 15:37:29 -0400 Subject: [PATCH] Re-order routes so '/' doesn't take precendence over /home; this bug fix was highly non-obvious to me. --- server.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index f1c66c0..0d01c45 100644 --- a/server.js +++ b/server.js @@ -36,12 +36,18 @@ app.engine('hbs', hbs.express4({ app.set('view engine', 'hbs'); app.set('views', __dirname + '/views'); -// temp testing for static home pages. +/******************************************************************************************************* +With this express setup, ordering of routes matters!!! It's 1st-come-1st-served. +If a more specific route is placed after a more general route, the general route will be chosen. +Not like nginx where the most specific match always wins. +Using express.Router() in express-4 might fix this, as would converting to hapi... +But, for now, order routes like this: + - static routes, ordered more specific to less specific + - dynamic routes, ordered more specific to less specific +********************************************************************************************************/ +// temp testing for static home page. app.get('/home', function(req, res) { - // Even when the winston call is the only thing in here...IT NO WORKY!!! - // But when I move it to be the first route in the file...IT DOES WORK!!! wtf? winston.info('GET /home'); - //res.status(404).send('Not found'); res.render('home', {}, function(err, html) { if(err !== null) { winston.error(err);