Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfd7afa

Browse files
authored
fix crash when headers is an array (#220)
1 parent 947fe4d commit bfd7afa

File tree

1 file changed

+11
-6
lines changed
  • packages/open-next/src/adapters/plugins/routing

1 file changed

+11
-6
lines changed

packages/open-next/src/adapters/plugins/routing/util.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,19 @@ export function fixCacheHeaderForHtmlPages(
5454
}
5555
}
5656

57-
export function fixSWRCacheHeader(headers: Record<string, string | undefined>) {
57+
export function fixSWRCacheHeader(
58+
headers: Record<string, string | string[] | undefined>,
59+
) {
5860
// WORKAROUND: `NextServer` does not set correct SWR cache headers — https://github.com/serverless-stack/open-next#workaround-nextserver-does-not-set-correct-swr-cache-headers
59-
if (headers["cache-control"]) {
60-
headers["cache-control"] = headers["cache-control"].replace(
61-
/\bstale-while-revalidate(?!=)/,
62-
"stale-while-revalidate=2592000", // 30 days
63-
);
61+
let cacheControl = headers["cache-control"];
62+
if (!cacheControl) return;
63+
if (Array.isArray(cacheControl)) {
64+
cacheControl = cacheControl.join(",");
6465
}
66+
headers["cache-control"] = cacheControl.replace(
67+
/\bstale-while-revalidate(?!=)/,
68+
"stale-while-revalidate=2592000", // 30 days
69+
);
6570
}
6671

6772
export function addOpenNextHeader(headers: Record<string, string | undefined>) {

0 commit comments

Comments
 (0)