Skip to content

Commit 3d253bb

Browse files
committed
fix issue and add a bypass
1 parent 5631308 commit 3d253bb

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

packages/open-next/src/core/routing/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@ export function fixCacheHeaderForHtmlPages(
288288
) {
289289
// We don't want to cache error pages
290290
if (rawPath === "/404" || rawPath === "/500") {
291+
if (process.env.OPEN_NEXT_DANGEROUSLY_SET_ERROR_HEADERS === "true") {
292+
return;
293+
}
291294
headers[CommonHeaders.CACHE_CONTROL] =
292295
"private, no-cache, no-store, max-age=0, must-revalidate";
293296
return;

packages/open-next/src/http/openNextResponse.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,15 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
390390
// For some reason, next returns the 500 error page with some cache-control headers
391391
// We need to fix that
392392
private fixHeadersForError() {
393+
if(process.env.OPEN_NEXT_DANGEROUSLY_SET_ERROR_HEADERS === 'true') {
394+
return;
395+
}
393396
// We only check for 404 and 500 errors
394397
// The rest should be errors that are handled by the user and they should set the cache headers themselves
395398
if (this.statusCode === 404 || this.statusCode === 500) {
396-
this.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
397-
this.setHeader("Pragma", "no-cache");
398-
this.setHeader("Expires", "0");
399+
// For some reason calling this.setHeader("Cache-Control", "no-cache, no-store, must-revalidate") does not work here
400+
// The function is not even called, i'm probably missing something obvious
401+
this.headers["cache-control"] = "private, no-cache, no-store, max-age=0, must-revalidate";
399402
}
400403
}
401404
}

0 commit comments

Comments
 (0)