Skip to content

Commit 312ea8b

Browse files
Maledongfhemberger
Maledong
authored andcommitted
[Fix] Ignore the case sensitive of Http Request (#1702)
Change Logs: 1) Fix:Due to Http Request string shouldn't be case sensitive. So convert them in lowercase in union and do comparation to make something like `zh-CN` = `zh-cn`. 2) Fix a typo. 3) Change some "let" to "const".
1 parent de5f7ef commit 312ea8b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

server.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,22 @@ const statics = chokidar.watch(path.join(__dirname, 'static'), opts)
3737

3838
// Redirect mechanism meant as a fix for languages where some pages
3939
// has not translated yet, therefore redirect to the english equivalent,
40-
// which ofc isn't the correct language, but better than a 404-page
40+
// which isn't the correct language, but better than a 404-page
4141
function redirectToEnglishUrl (req, res) {
4242
return () => {
43-
const isAlreadyEnglish = req.url.startsWith('/en')
44-
const urlContainsLanguage = req.url.split('/').length > 2
43+
// Union the Url to lower case (ignore the case sensitive)
44+
// E.g: `zh-cn` equals to `zh-CN`
45+
const url = req.url.toLowerCase()
46+
47+
const isAlreadyEnglish = url.startsWith('/en')
48+
const urlContainsLanguage = url.split('/').length > 2
4549

4650
if (isAlreadyEnglish || !urlContainsLanguage) {
4751
res.writeHead(404, 'Not found')
4852
return res.end()
4953
}
5054

51-
let englishUrl = req.url.replace(/^\/\w+\//, '/en/')
55+
const englishUrl = url.replace(/^\/\w+\//, '/en/')
5256

5357
res.writeHead(302, {
5458
location: englishUrl

0 commit comments

Comments
 (0)