@@ -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
@@ -403,10 +403,11 @@ export function fixISRHeaders(headers: OutgoingHttpHeaders) {
403403 * @__PURE__
404404 */
405405export function createServerResponse (
406- internalEvent : InternalEvent ,
406+ routingResult : RoutingResult ,
407407 headers : Record < string , string | string [ ] | undefined > ,
408408 responseStream ?: StreamCreator ,
409409) {
410+ const internalEvent = routingResult . internalEvent ;
410411 return new OpenNextNodeResponse (
411412 ( _headers ) => {
412413 fixCacheHeaderForHtmlPages ( internalEvent , _headers ) ;
@@ -420,34 +421,29 @@ export function createServerResponse(
420421 internalEvent . rawPath ,
421422 _headers ,
422423 ) ;
423- await invalidateCDNOnRequest ( {
424- rawPath : internalEvent . rawPath ,
425- isIsrRevalidation : internalEvent . headers [ "x-isr" ] === "1" ,
426- headers : _headers ,
427- } ) ;
424+ await invalidateCDNOnRequest ( routingResult , _headers ) ;
428425 } ,
429426 responseStream ,
430427 headers ,
431428 ) ;
432429}
433430
434431// This function is used only for `res.revalidate()`
435- export async function invalidateCDNOnRequest ( params : {
436- //TODO: use the initialPath instead of rawPath, a rewrite could have happened and would make cdn invalidation fail
437- rawPath : string ;
438- isIsrRevalidation ?: boolean ;
439- headers : OutgoingHttpHeaders ;
440- } ) {
441- const { rawPath, isIsrRevalidation, headers } = params ;
432+ export async function invalidateCDNOnRequest (
433+ params : RoutingResult ,
434+ headers : OutgoingHttpHeaders ,
435+ ) {
436+ const { internalEvent, initialPath, resolvedRoutes } = params ;
437+ const isIsrRevalidation = internalEvent . headers [ "x-isr" ] === "1" ;
442438 if (
443439 ! isIsrRevalidation &&
444440 headers [ CommonHeaders . NEXT_CACHE ] === "REVALIDATED"
445441 ) {
446442 await globalThis . cdnInvalidationHandler . invalidatePaths ( [
447443 {
448- path : rawPath ,
449- //TODO: Here we assume that the path is for page router, this might not be the case
450- isAppRouter : false ,
444+ initialPath ,
445+ rawPath : internalEvent . rawPath ,
446+ resolvedRoutes ,
451447 } ,
452448 ] ) ;
453449 }
0 commit comments