Created
January 17, 2023 15:23
-
-
Save gungoren/58dfac8037bd58139c6222cc3674c7f6 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 olduri = request.uri; | |
let newuri = olduri; | |
const country = request.headers["cloudfront-viewer-country"][0].value | |
const strIsPrimary = request.origin.s3.customHeaders.primary[0].value | |
const isPrimary = strIsPrimary === true || ['true','yes','1'].indexOf(strIsPrimary.toString().toLowerCase()) > -1 | |
if (isPrimary) { | |
newuri = `/${country}${olduri}`; | |
} | |
console.log("IsPrimary : " + isPrimary + " Old URI: " + olduri + " New URI: " + newuri + " country : " + country); | |
request.uri = newuri; | |
return callback(null, request); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment