@@ -8,8 +8,8 @@ import { OpenNextNodeResponse } from "http/openNextResponse.js";
88import { parseHeaders } from "http/util.js" ;
99import type { MiddlewareManifest } from "types/next-types" ;
1010import type {
11- InternalEvent ,
1211 InternalResult ,
12+ RoutingResult ,
1313 StreamCreator ,
1414} from "types/open-next.js" ;
1515
@@ -401,10 +401,11 @@ export function fixISRHeaders(headers: OutgoingHttpHeaders) {
401401 * @__PURE__
402402 */
403403export function createServerResponse (
404- internalEvent : InternalEvent ,
404+ routingResult : RoutingResult ,
405405 headers : Record < string , string | string [ ] | undefined > ,
406406 responseStream ?: StreamCreator ,
407407) {
408+ const internalEvent = routingResult . internalEvent ;
408409 return new OpenNextNodeResponse (
409410 ( _headers ) => {
410411 fixCacheHeaderForHtmlPages ( internalEvent . rawPath , _headers ) ;
@@ -418,34 +419,29 @@ export function createServerResponse(
418419 internalEvent . rawPath ,
419420 _headers ,
420421 ) ;
421- await invalidateCDNOnRequest ( {
422- rawPath : internalEvent . rawPath ,
423- isIsrRevalidation : internalEvent . headers [ "x-isr" ] === "1" ,
424- headers : _headers ,
425- } ) ;
422+ await invalidateCDNOnRequest ( routingResult , _headers ) ;
426423 } ,
427424 responseStream ,
428425 headers ,
429426 ) ;
430427}
431428
432429// This function is used only for `res.revalidate()`
433- export async function invalidateCDNOnRequest ( params : {
434- //TODO: use the initialPath instead of rawPath, a rewrite could have happened and would make cdn invalidation fail
435- rawPath : string ;
436- isIsrRevalidation ?: boolean ;
437- headers : OutgoingHttpHeaders ;
438- } ) {
439- const { rawPath, isIsrRevalidation, headers } = params ;
430+ export async function invalidateCDNOnRequest (
431+ params : RoutingResult ,
432+ headers : OutgoingHttpHeaders ,
433+ ) {
434+ const { internalEvent, initialPath, resolvedRoutes } = params ;
435+ const isIsrRevalidation = internalEvent . headers [ "x-isr" ] === "1" ;
440436 if (
441437 ! isIsrRevalidation &&
442438 headers [ CommonHeaders . NEXT_CACHE ] === "REVALIDATED"
443439 ) {
444440 await globalThis . cdnInvalidationHandler . invalidatePaths ( [
445441 {
446- path : rawPath ,
447- //TODO: Here we assume that the path is for page router, this might not be the case
448- isAppRouter : false ,
442+ initialPath ,
443+ rawPath : internalEvent . rawPath ,
444+ resolvedRoutes ,
449445 } ,
450446 ] ) ;
451447 }
0 commit comments