@@ -182,6 +182,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
182
182
: [ ...initialCookies , ...this . _cookies ] ;
183
183
}
184
184
this . fixHeaders ( this . headers ) ;
185
+ this . fixHeadersForError ( ) ;
185
186
186
187
// We need to fix the set-cookie header here
187
188
this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
@@ -275,6 +276,7 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
275
276
getFixedHeaders ( ) : OutgoingHttpHeaders {
276
277
// Do we want to apply this on writeHead?
277
278
this . fixHeaders ( this . headers ) ;
279
+ this . fixHeadersForError ( ) ;
278
280
// This way we ensure that the cookies are correct
279
281
this . headers [ SET_COOKIE_HEADER ] = this . _cookies ;
280
282
return this . headers ;
@@ -384,4 +386,20 @@ export class OpenNextNodeResponse extends Transform implements ServerResponse {
384
386
//TODO: test to see if we need to call end here
385
387
return this ;
386
388
}
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
+ if ( process . env . OPEN_NEXT_DANGEROUSLY_SET_ERROR_HEADERS === "true" ) {
394
+ return ;
395
+ }
396
+ // We only check for 404 and 500 errors
397
+ // The rest should be errors that are handled by the user and they should set the cache headers themselves
398
+ if ( this . statusCode === 404 || this . statusCode === 500 ) {
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" ] =
402
+ "private, no-cache, no-store, max-age=0, must-revalidate" ;
403
+ }
404
+ }
387
405
}
0 commit comments