@@ -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,20 @@ 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+ 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+ }
387405}
0 commit comments