From 6f7c1308b913027b74265c844639bcc1f439a1fc Mon Sep 17 00:00:00 2001 From: Nicolas Dorseuil Date: Sun, 25 May 2025 16:32:47 +0200 Subject: [PATCH] fix cache control for static page with base path --- .changeset/afraid-trees-bathe.md | 5 +++++ packages/open-next/src/core/routing/util.ts | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/afraid-trees-bathe.md diff --git a/.changeset/afraid-trees-bathe.md b/.changeset/afraid-trees-bathe.md new file mode 100644 index 000000000..5aee5409d --- /dev/null +++ b/.changeset/afraid-trees-bathe.md @@ -0,0 +1,5 @@ +--- +"@opennextjs/aws": patch +--- + +fix cache control headers for fully static page with base path diff --git a/packages/open-next/src/core/routing/util.ts b/packages/open-next/src/core/routing/util.ts index 70ae53027..ddc82cd10 100644 --- a/packages/open-next/src/core/routing/util.ts +++ b/packages/open-next/src/core/routing/util.ts @@ -245,7 +245,9 @@ export function fixCacheHeaderForHtmlPages( // https://opennext.js.org/aws/v2/advanced/workaround#workaround-nextserver-does-not-set-cache-headers-for-html-pages // Requests containing an `x-middleware-prefetch` header must not be cached if ( - HtmlPages.includes(localizedPath) && + HtmlPages.find( + (path) => `${NextConfig.basePath ?? ""}${path}` === localizedPath, + ) && !internalEvent.headers["x-middleware-prefetch"] ) { headers[CommonHeaders.CACHE_CONTROL] =