Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Ignore the case sensitive of Http Request #1702

Merged
merged 1 commit into from Jun 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ const statics = chokidar.watch(path.join(__dirname, 'static'), opts)

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

const isAlreadyEnglish = url.startsWith('/en')
const urlContainsLanguage = url.split('/').length > 2

if (isAlreadyEnglish || !urlContainsLanguage) {
res.writeHead(404, 'Not found')
return res.end()
}

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

res.writeHead(302, {
location: englishUrl
Expand Down