Skip to content

Commit

Permalink
fix: handle trailing slash mismatch for redirects
Browse files Browse the repository at this point in the history
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
  • Loading branch information
dvdksn committed Aug 24, 2023
1 parent 1b8a23c commit bf4a605
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions _releaser/cloudfront-lambda-redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
exports.handler = (event, context, callback) => {
//console.log("event", JSON.stringify(event));
const request = event.Records[0].cf.request;
const requestUrl = request.uri.replace(/\/$/, "")

const redirects = JSON.parse(`{{.RedirectsJSON}}`);
for (let key in redirects) {
if (key !== request.uri) {
const redirectTarget = key.replace(/\/$/, "")
if (redirectTarget !== requestUrl) {
continue;
}
//console.log(`redirect: ${request.uri} to ${redirects[key]}`);
//console.log(`redirect: ${requestUrl} to ${redirects[key]}`);
const response = {
status: '301',
statusDescription: 'Moved Permanently',
Expand Down

0 comments on commit bf4a605

Please sign in to comment.