cloudhead/node-static — pull request #56 by TeeTeeHaa (2012-06-24 15:45:31+00:00)
Title: missing trailing slash in URL when using default file "index.html"

This issue is for node-static version 0.5.9.

In case the URL does not contain a file node-static tries to serve the default file "index.html". In case the file exists it does not matter whether the URL contains a trailing slash or not:

http://localhost/path/ ==> serves index.html
http://localhost/path ==> serves index.html

But if the file (index.html) includes some other files, e.x. a JS script file (code.js), the loading of the JS script file will fail with an "404 Not Found" error because the browser is assuming a wrong path for the JS script file:

http://localhost/path/ ==> serves index.html and serves code.js
http://localhost/path ==> serves index.html and serves 404 for code.js

The same examples in Apache look like this:

http://localhost/path/ ==> serves index.html and serves code.js
http://localhost/path ==> serves "301 Moved Permanently" with a header "Location" containing the URL including the trailing slash where the browser then goes to

I've written a proof-of-concept to demonstrate this bug:

https://gist.github.com/2983697

This pull request includes a fix for this bug. Disclaimer: I did not test that fix excessively so you should have a look yourself before putting this in a productive system.