Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions hack/releaser/cloudfront-lambda-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
exports.handler = (event, context, callback) => {
//console.log("event", JSON.stringify(event));
const request = event.Records[0].cf.request;
// Trim trailing slash and collapse redundant slashes
const normalizedUri = request.uri.replace(/\/$/, "").replaceAll(/\/{2,}/g, "/")
const requestUrl = request.uri.replace(/\/$/, "")

const redirects = JSON.parse(`{{.RedirectsJSON}}`);
for (let key in redirects) {
const redirectTarget = key.replace(/\/$/, "")
if (redirectTarget !== normalizedUri) {
if (redirectTarget !== requestUrl) {
continue;
}
//console.log(`redirect: ${normalizedUri} to ${redirects[key]}`);
//console.log(`redirect: ${requestUrl} to ${redirects[key]}`);
const response = {
status: '301',
statusDescription: 'Moved Permanently',
Expand Down Expand Up @@ -53,6 +52,5 @@ exports.handler = (event, context, callback) => {
return
}

request.uri = normalizedUri
callback(null, request);
};