Skip to content

Commit

Permalink
fix(netlify): match ISR route rules when path has a query string (#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
serhalp committed May 16, 2024
1 parent 944dcde commit 6adc84c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/presets/netlify/runtime/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const handler = async (req: Request): Promise<Response> => {
});

const headers = normalizeResponseHeaders({
...getCacheHeaders(relativeUrl),
...getCacheHeaders(url.pathname),
...r.headers,
});

Expand Down
3 changes: 3 additions & 0 deletions src/runtime/route-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ type DeepReadonly<T> = T extends Record<string, any>
? ReadonlyArray<DeepReadonly<U>>
: T;

/**
* @param path - The path to match against route rules. This should not contain a query string.
*/
export function getRouteRulesForPath(
path: string
): DeepReadonly<NitroRouteRules> {
Expand Down
9 changes: 9 additions & 0 deletions test/presets/netlify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ describe("nitro:preset:netlify", async () => {
(headers as Record<string, string>)["netlify-cdn-cache-control"]
).not.toBeDefined();
});
// Regression test for https://github.com/unjs/nitro/issues/2431
it("matches paths with a query string", async () => {
const { headers } = await callHandler({
url: "/rules/isr-ttl?foo=bar",
});
expect(
(headers as Record<string, string>)["netlify-cdn-cache-control"]
).toBe("public, max-age=60, stale-while-revalidate=31536000");
});
}
);
});

0 comments on commit 6adc84c

Please sign in to comment.