Skip to content

Instantly share code, notes, and snippets.

@gungoren
Created January 17, 2023 15:23
Show Gist options
  • Save gungoren/58dfac8037bd58139c6222cc3674c7f6 to your computer and use it in GitHub Desktop.
Save gungoren/58dfac8037bd58139c6222cc3674c7f6 to your computer and use it in GitHub Desktop.
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