mirror of
https://github.com/withastro/astro.git
synced 2025-03-10 23:01:26 -05:00
fix: ISR opt out for routes with rest parameters (#373)
Co-authored-by: Ben Holmes <hey@bholmes.dev>
This commit is contained in:
parent
052dfd9adb
commit
bf397d05cb
4 changed files with 40 additions and 18 deletions
|
@ -45,25 +45,31 @@ function getParts(part: string, file: string) {
|
|||
// 2022-04-26
|
||||
function getMatchPattern(segments: RoutePart[][]) {
|
||||
return segments
|
||||
.map((segment) => {
|
||||
return segment[0].spread
|
||||
.map((segment, segmentIndex) => {
|
||||
return segment.length === 1 && segment[0].spread
|
||||
? '(?:\\/(.*?))?'
|
||||
: segment
|
||||
.map((part) => {
|
||||
if (part)
|
||||
return part.dynamic
|
||||
? '([^/]+?)'
|
||||
: part.content
|
||||
.normalize()
|
||||
.replace(/\?/g, '%3F')
|
||||
.replace(/#/g, '%23')
|
||||
.replace(/%5B/g, '[')
|
||||
.replace(/%5D/g, ']')
|
||||
.replace(/[*+?^${}()|[\]\\]/g, '\\$&');
|
||||
})
|
||||
.join('');
|
||||
: // Omit leading slash if segment is a spread.
|
||||
// This is handled using a regex in Astro core.
|
||||
// To avoid complex data massaging, we handle in-place here.
|
||||
(segmentIndex === 0 ? '' : '/') +
|
||||
segment
|
||||
.map((part) => {
|
||||
if (part)
|
||||
return part.spread
|
||||
? '(.*?)'
|
||||
: part.dynamic
|
||||
? '([^/]+?)'
|
||||
: part.content
|
||||
.normalize()
|
||||
.replace(/\?/g, '%3F')
|
||||
.replace(/#/g, '%23')
|
||||
.replace(/%5B/g, '[')
|
||||
.replace(/%5D/g, ']')
|
||||
.replace(/[*+?^${}()|[\]\\]/g, '\\$&');
|
||||
})
|
||||
.join('');
|
||||
})
|
||||
.join('/');
|
||||
.join('');
|
||||
}
|
||||
|
||||
function getReplacePattern(segments: RoutePart[][]) {
|
||||
|
|
|
@ -7,7 +7,7 @@ export default defineConfig({
|
|||
isr: {
|
||||
bypassToken: "1c9e601d-9943-4e7c-9575-005556d774a8",
|
||||
expiration: 120,
|
||||
exclude: ["/two", "/excluded/[dynamic]"]
|
||||
exclude: ["/two", "/excluded/[dynamic]", "/excluded/[...rest]"]
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
8
packages/integrations/vercel/test/fixtures/isr/src/pages/excluded/[...rest].astro
vendored
Normal file
8
packages/integrations/vercel/test/fixtures/isr/src/pages/excluded/[...rest].astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Rest</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Rest</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -37,6 +37,10 @@ describe('ISR', () => {
|
|||
src: '^/excluded/([^/]+?)$',
|
||||
dest: '_render',
|
||||
},
|
||||
{
|
||||
src: '^/excluded(?:\\/(.*?))?$',
|
||||
dest: '_render',
|
||||
},
|
||||
{
|
||||
src: '^\\/_image$',
|
||||
dest: '_render',
|
||||
|
@ -45,6 +49,10 @@ describe('ISR', () => {
|
|||
src: '^\\/excluded\\/([^/]+?)\\/?$',
|
||||
dest: '/_isr?x_astro_path=$0',
|
||||
},
|
||||
{
|
||||
src: '^\\/excluded(?:\\/(.*?))?\\/?$',
|
||||
dest: '/_isr?x_astro_path=$0',
|
||||
},
|
||||
{
|
||||
src: '^\\/one\\/?$',
|
||||
dest: '/_isr?x_astro_path=$0',
|
||||
|
|
Loading…
Add table
Reference in a new issue