case sensitive routing not working

When I write app.set('case sensitive routing', true);, the server still works when receiving requests for /Path and /path even when the route is router.get('/path/:value([a-z]+)', router_handler);. Also I’d like value only allows lower letters, but it receives upper letters. What am I doing wrong?.

Author: Fantashit

3 thoughts on “case sensitive routing not working

  1. I made it work using:

    router = express.Router({
      caseSensitive: true
    });

    instead of enabling case sensitive routing on app.

  2. As for the app.set('case sensitive routing', true); issue; I would need to see a full piece of code to reproduce, but most likely what you are seeing is that most core settings like “case sensitive routing” need to be set before your first app.use(), or first route, otherwise they have no effect.

  3. Ok, I understand now 🙂 So yes, with Express 4, when you do express.Router() in a different file, it doesn’t have the same settings as the app’s router (the case sensitive routing setting, in this case). I was actually thinking as part of Express 5 to add a app.createRouter(opts) that would default the options to the same as the app itself, allowing you to keep the settings downward, though it wouldn’t really help in your case.

    Each router instance is basically intended to be isolated from each other, to promote code re-use (because, well, it’s hard to re-use a router in an app that decides to change the routing semantics :). like if you had your router and it expected case sensitive routes, but then you tried to re-use your router an an app that did not have case sensitive routes and it couldn’t be changed for legacy reasons, etc.).

Comments are closed.