-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(netlify-legacy): exclude static paths from SSR function
Backporting #2822 to the netlify-legacy preset. Since it's using "v1" Netlify Functions (https://docs.netlify.com/functions/lambda-compatibility), it doesn't have access to `excludedPath` and `preferStatic`, so we implement this with redirects.
- Loading branch information
Showing
4 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { generateCatchAllRedirects } from "../../src/presets/netlify/legacy/utils"; | ||
|
||
describe("generateCatchAllRedirects", () => { | ||
it("returns empty string if `catchAllPath` is not defined", () => { | ||
expect(generateCatchAllRedirects([], undefined)).toEqual(""); | ||
}); | ||
|
||
it("includes a redirect from `/*` to `catchAllPath` if defined", () => { | ||
expect(generateCatchAllRedirects([], "/catch-all")).toEqual( | ||
"/* /catch-all 200" | ||
); | ||
}); | ||
|
||
it("includes a splat redirect for each non-fallthrough non-root public asset path, BEFORE the catch-all", () => { | ||
const publicAssets = [ | ||
{ | ||
fallthrough: true, | ||
baseURL: "with-fallthrough", | ||
dir: "with-fallthrough-dir", | ||
maxAge: 0, | ||
}, | ||
{ | ||
fallthrough: true, | ||
dir: "with-fallthrough-no-baseURL-dir", | ||
maxAge: 0, | ||
}, | ||
{ | ||
fallthrough: false, | ||
dir: "no-fallthrough-no-baseURL-dir", | ||
maxAge: 0, | ||
}, | ||
{ | ||
fallthrough: false, | ||
dir: "no-fallthrough-root-baseURL-dir", | ||
baseURL: "/", | ||
maxAge: 0, | ||
}, | ||
{ | ||
baseURL: "with-default-fallthrough", | ||
dir: "with-default-fallthrough-dir", | ||
maxAge: 0, | ||
}, | ||
{ | ||
fallthrough: false, | ||
baseURL: "nested/no-fallthrough", | ||
dir: "nested/no-fallthrough-dir", | ||
maxAge: 0, | ||
}, | ||
]; | ||
expect( | ||
generateCatchAllRedirects(publicAssets, "/catch-all") | ||
).toMatchInlineSnapshot( | ||
` | ||
"/with-default-fallthrough/* /with-default-fallthrough/:splat 200 | ||
/nested/no-fallthrough/* /nested/no-fallthrough/:splat 200 | ||
/* /catch-all 200" | ||
`.trim() | ||
); | ||
}); | ||
}); |