문제

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 ??

도움이 되었습니까?

해결책

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);

다른 팁

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});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top