Search code examples
linuxnode.jsmacosexpresscase-sensitive

Case sensitivity of Node.js Express static assets


How can I set whether the routing for express.static is case sensitive? e.g. whether Express should handle a request for image.jpeg by serving up a local file called Image.jpeg.

There is a caseSensitive option when calling express.Router([options]) (as defined at http://expressjs.com/en/4x/api.html) but this is not an option when calling express.static(root, [options]) (documentation at the same link).

By default, I get different behaviour serving static files from case insensitive volumes (/Mac OS X) to case sensitive volumes (/Linux). This results in inconsistent errors in our application - where something with a case mismatch works locally under Mac OS X but fails when deploying to the Linux server.


Solution

  • I was given also some advice for a simple alternative solution:

    Set a policy that all your static files and paths should be in lowercase.

    Enforce the policy on the files by adding a build step that checks them.

    Enforce the policy on requests by adding some middleware that rejects requests to the static folder if any uppercase characters are found in the path.