From 63728bea77f032b5f886613b7cec0f9fd1941920 Mon Sep 17 00:00:00 2001 From: ajfisher Date: Sun, 22 Sep 2024 17:27:47 +1000 Subject: [PATCH] fix: add handlers for the authourl addition. Closes #225 --- app/handlers/gatsby_index_redirect.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/handlers/gatsby_index_redirect.mjs b/app/handlers/gatsby_index_redirect.mjs index 132cf9b..6fbcbf0 100644 --- a/app/handlers/gatsby_index_redirect.mjs +++ b/app/handlers/gatsby_index_redirect.mjs @@ -8,11 +8,24 @@ export const handler = async (event) => { const request = event.Records[0].cf.request; const { uri } = request; - if (uri.endsWith('/')) { + if (uri.endsWith('%7Bauthourl%7D')) { + // this is dealing with a bunch of the 404 errors we see where there's a + // {authourl} appended to the end of the request - just remove this + request.uri = uri.replace('%7Bauthourl%7D', ''); + } + + if (uri.endsWith('{authourl}')) { + // this is dealing with a bunch of the 404 errors we see where there's a + // {authourl} appended to the end of the request - just remove this + request.uri = uri.replace('{authourl}', ''); + } + + if (request.uri.endsWith('/')) { request.uri += 'index.html'; - } else if (!uri.includes('.')) { + } else if (!request.uri.includes('.')) { request.uri += '/index.html'; } return request; }; +