Skip to content

Commit 5631308

Browse files
committed
fix 500 error page cached
1 parent 8f4b67a commit 5631308

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
182182
: [...initialCookies, ...this._cookies];
183183
}
184184
this.fixHeaders(this.headers);
185+
this.fixHeadersForError();
185186

186187
// We need to fix the set-cookie header here
187188
this.headers[SET_COOKIE_HEADER] = this._cookies;
@@ -275,6 +276,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
275276
getFixedHeaders(): OutgoingHttpHeaders {
276277
// Do we want to apply this on writeHead?
277278
this.fixHeaders(this.headers);
279+
this.fixHeadersForError();
278280
// This way we ensure that the cookies are correct
279281
this.headers[SET_COOKIE_HEADER] = this._cookies;
280282
return this.headers;
@@ -384,4 +386,16 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
384386
//TODO: test to see if we need to call end here
385387
return this;
386388
}
389+
390+
// For some reason, next returns the 500 error page with some cache-control headers
391+
// We need to fix that
392+
private fixHeadersForError() {
393+
// We only check for 404 and 500 errors
394+
// The rest should be errors that are handled by the user and they should set the cache headers themselves
395+
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+
}
400+
}
387401
}

0 commit comments

Comments
 (0)