From bcba2669b9c359b076d84d44991e46310b98afff Mon Sep 17 00:00:00 2001 From: christian-calabrese Date: Tue, 29 Oct 2024 14:54:40 +0100 Subject: [PATCH] [DEV-1988] - Added exceptions list to map edge cases where extensions false positives may cause 404 (#1211) * fix: added exceptions list to map edge cases where extensions false positives may cause 404 * chore: changeset added --- .changeset/proud-mails-hide.md | 5 +++++ .../src/viewer-request-handler.ts | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/proud-mails-hide.md diff --git a/.changeset/proud-mails-hide.md b/.changeset/proud-mails-hide.md new file mode 100644 index 0000000000..8bc2852a3e --- /dev/null +++ b/.changeset/proud-mails-hide.md @@ -0,0 +1,5 @@ +--- +"cloudfront-functions": patch +--- + +Fixed .bollo ending urls causing 404 diff --git a/apps/cloudfront-functions/src/viewer-request-handler.ts b/apps/cloudfront-functions/src/viewer-request-handler.ts index ecd9ce1643..bcca874095 100644 --- a/apps/cloudfront-functions/src/viewer-request-handler.ts +++ b/apps/cloudfront-functions/src/viewer-request-handler.ts @@ -13,18 +13,24 @@ const handler = ( const { request } = event; const uri = request.uri; - // Check if the uri refers to a gitbook assets + // Check if the uri refers to a gitbook asset const isGitbookAssets = uri.startsWith('/gitbook/docs'); const isWoff2 = uri.endsWith('.woff2'); // woff2 is a font format const uriEndsWithSlash = uri.endsWith('/'); const isHomepage = uri === '/'; + // List of special cases (add more as needed) + const specialCases: string[] = ['.bollo']; + + // Function to check if URI ends with any of the special cases + const isSpecialCase = specialCases.some(caseExt => uri.endsWith(caseExt)); + if (!isHomepage) { if (uriEndsWithSlash) { request.uri = uri.replace(/\/$/, ''); } - // Add the .html extension if missing - if (!isGitbookAssets && !isWoff2 && !/\.[a-zA-Z]+$/.test(uri)) { + // Always add .html if there's no file extension, including special cases + if (!isGitbookAssets && !isWoff2 && (!/\.[a-zA-Z]+$/.test(uri) || isSpecialCase)) { request.uri += '.html'; } } @@ -34,4 +40,4 @@ const handler = ( // do nothing return event.request; } -}; +}; \ No newline at end of file