Created
April 16, 2019 11:21
-
-
Save poudelmadhav/7d4221188eaef718732366aad7b5a374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
if(request.uri == '/') { | |
if (typeof headers['accept-language'] !== 'undefined') { | |
const supportedLanguages = headers['accept-language'][0].value; | |
console.log('Supported languages:', supportedLanguages); | |
if(supportedLanguages.startsWith('en')){ | |
callback(null, redirect('/en/index.html')); | |
} else if(supportedLanguages.startsWith('ja')){ | |
callback(null, redirect('/ja/index.html')); | |
} else if(supportedLanguages.startsWith('fr')){ | |
callback(null, redirect('/fr/')); | |
} else if(supportedLanguages.startsWith('it')){ | |
callback(null, redirect('/it/')); | |
} else if(supportedLanguages.startsWith('pl')){ | |
callback(null, redirect('/pl-PL/')); | |
} else { | |
callback(null, redirect('/ja/index.html')); | |
} | |
} else { | |
callback(null, redirect('/ja/index.html')); | |
} | |
} else { | |
callback(null, request); | |
} | |
}; | |
function redirect (to) { | |
return { | |
status: '301', | |
statusDescription: 'redirect to browser language', | |
headers: { | |
location: [{ key: 'Location', value: to }] | |
} | |
}; | |
} |
roshanadhikari2073
commented
Feb 3, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment