Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs express - case sensitive URL's

How to make URL's case sensitive?

app.get()

app.get('/([a-z]{2}/)api*', function(request, response){});

Here this app.get() catch both /EN/api /eN/api

What can I do so it only catches lower case URL's like /en/api ??

like image 594
clarkk Avatar asked Jan 19 '14 12:01

clarkk


2 Answers

app.set('case sensitive routing', true);

works only if u don't use in other files

const express = require('express');
const router = express.Router();

if in our case same as above, just do this (in each file):

const express = require('express');
const router = express.Router({caseSensitive: true});
like image 40
Никита Середа Avatar answered Sep 19 '22 12:09

Никита Середа


From express.js api docs

case sensitive routing - Enable case sensitivity, disabled by default, treating "/Foo" and "/foo" as the same

You can change the defaults like so:

app.set('case sensitive routing', true);
like image 123
Ilan Frumer Avatar answered Sep 20 '22 12:09

Ilan Frumer