app.get("/:name?/:group?", function(req, res){...
is matching files that are in my public directory. So if I include a stylesheet:
<link type="text/css" href="/stylesheets/style.css" />
Node will match /stylesheets/style.css and assign name the value stylesheets and group the value style.css.
What's the best way to avoid this?
The easiest thing may be to make sure that express runs the static provider middleware prior to the router middleware. You can do this by doing:
app.use(express.static(__dirname + '/public'));
app.use(app.router);
That way the static file will find it and respond and the router won't be executed. I've had similar confusion with the router's default position (last) screwing up with my compilation of coffeescript files. FYI there are docs on this here (search the page for app.router
and you'll see an explanatory paragraph.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With