From 0c3746578fa5cfdf59ff21d5d02879e867192043 Mon Sep 17 00:00:00 2001 From: Finn <65142636+finnholland@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:59:03 +1030 Subject: [PATCH] Added leading slash to Location URL response (#1411) --- .../prerender-fargate/lib/prerender/server.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/prerender-fargate/lib/prerender/server.js b/packages/prerender-fargate/lib/prerender/server.js index 4e6bd0d4..c0177c29 100644 --- a/packages/prerender-fargate/lib/prerender/server.js +++ b/packages/prerender-fargate/lib/prerender/server.js @@ -238,11 +238,16 @@ server.use({ } let headerMatch = headerMatchRegex.exec(head); - while (headerMatch) { - s3Metadata.location = - headerMatch[1].toLowerCase() == "location" - ? he.decode(headerMatch[2] || headerMatch[4]) - : ""; + while (headerMatch) { + const decoded = he.decode(headerMatch[2] || headerMatch[4]) + if (headerMatch[1].toLowerCase() == "location") { + s3Metadata.location = decoded + if (!decoded.startsWith('http') && !decoded.startsWith('/')) { + s3Metadata.location = '/' + s3Metadata.location + } + } else { + s3Metadata.location = "" + } res.setHeader(headerMatch[1] || headerMatch[3], s3Metadata.location); req.prerender.content = req.prerender.content .toString()