Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
a679a1e1
Unverified
Commit
a679a1e1
authored
Aug 06, 2022
by
JJ Kasper
Committed by
GitHub
Aug 06, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix catchall rewrites for _next/data routes (#39370)
* Fix catchall rewrites for _next/data routes * update check
parent
d008f655
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
1 deletion
+73
-1
base-server.ts
packages/next/server/base-server.ts
+1
-0
router.ts
packages/next/server/router.ts
+8
-1
next.config.js
test/integration/custom-routes/next.config.js
+4
-0
[slug].js
test/integration/custom-routes/pages/overridden/[slug].js
+18
-0
index.test.js
test/integration/custom-routes/test/index.test.js
+42
-0
No files found.
packages/next/server/base-server.ts
View file @
a679a1e1
...
@@ -734,6 +734,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
...
@@ -734,6 +734,7 @@ export default abstract class Server<ServerOptions extends Options = Options> {
match
:
getPathMatch
(
'/_next/data/:path*'
),
match
:
getPathMatch
(
'/_next/data/:path*'
),
type
:
'route'
,
type
:
'route'
,
name
:
'_next/data catchall'
,
name
:
'_next/data catchall'
,
check
:
true
,
fn
:
async
(
req
,
res
,
params
,
_parsedUrl
)
=>
{
fn
:
async
(
req
,
res
,
params
,
_parsedUrl
)
=>
{
// Make sure to 404 for /_next/data/ itself and
// Make sure to 404 for /_next/data/ itself and
// we also want to 404 if the buildId isn't correct
// we also want to 404 if the buildId isn't correct
...
...
packages/next/server/router.ts
View file @
a679a1e1
...
@@ -222,7 +222,14 @@ export default class Router {
...
@@ -222,7 +222,14 @@ export default class Router {
this
.
catchAllMiddleware
this
.
catchAllMiddleware
const
allRoutes
=
[
const
allRoutes
=
[
...(
middlewareCatchAllRoute
...(
middlewareCatchAllRoute
?
this
.
fsRoutes
.
filter
((
r
)
=>
r
.
name
===
'_next/data catchall'
)
?
this
.
fsRoutes
.
filter
((
r
)
=>
r
.
name
===
'_next/data catchall'
)
.
map
((
r
)
=>
{
return
{
...
r
,
check
:
false
,
}
})
:
[]),
:
[]),
...
this
.
headers
,
...
this
.
headers
,
...
this
.
redirects
,
...
this
.
redirects
,
...
...
test/integration/custom-routes/next.config.js
View file @
a679a1e1
...
@@ -204,6 +204,10 @@ module.exports = {
...
@@ -204,6 +204,10 @@ module.exports = {
source
:
'/blog/about'
,
source
:
'/blog/about'
,
destination
:
'/hello'
,
destination
:
'/hello'
,
},
},
{
source
:
'/overridden/:path*'
,
destination
:
'/overridden'
,
},
],
],
beforeFiles
:
[
beforeFiles
:
[
{
{
...
...
test/integration/custom-routes/pages/overridden/[slug].js
0 → 100644
View file @
a679a1e1
export
default
function
Page
()
{
return
<
p
>
/overriden/
[
slug
]
<
/p
>
}
export
function
getStaticProps
({
params
})
{
return
{
props
:
{
params
,
},
}
}
export
function
getStaticPaths
()
{
return
{
paths
:
[],
fallback
:
'blocking'
,
}
}
test/integration/custom-routes/test/index.test.js
View file @
a679a1e1
...
@@ -39,6 +39,22 @@ let appPort
...
@@ -39,6 +39,22 @@ let appPort
let
app
let
app
const
runTests
=
(
isDev
=
false
)
=>
{
const
runTests
=
(
isDev
=
false
)
=>
{
it
(
'should not rewrite for _next/data route when a match is found'
,
async
()
=>
{
const
initial
=
await
fetchViaHTTP
(
appPort
,
'/overridden/first'
)
expect
(
initial
.
status
).
toBe
(
200
)
expect
(
await
initial
.
text
()).
toContain
(
'this page is overridden'
)
const
nextData
=
await
fetchViaHTTP
(
appPort
,
`/_next/data/
${
buildId
}
/overridden/first.json`
)
expect
(
nextData
.
status
).
toBe
(
200
)
expect
(
await
nextData
.
json
()).
toEqual
({
pageProps
:
{
params
:
{
slug
:
'first'
}
},
__N_SSG
:
true
,
})
})
it
(
'should handle has query encoding correctly'
,
async
()
=>
{
it
(
'should handle has query encoding correctly'
,
async
()
=>
{
for
(
const
expected
of
[
for
(
const
expected
of
[
{
{
...
@@ -1271,6 +1287,18 @@ const runTests = (isDev = false) => {
...
@@ -1271,6 +1287,18 @@ const runTests = (isDev = false) => {
slug
:
'slug'
,
slug
:
'slug'
,
},
},
},
},
{
dataRouteRegex
:
`^\\/_next\\/data\\/
${
escapeRegex
(
buildId
)}
\\/overridden\\/([^\\/]+?)\\.json$`
,
namedDataRouteRegex
:
`^/_next/data/
${
escapeRegex
(
buildId
)}
/overridden/(?<slug>[^/]+?)\\.json$`
,
page
:
'/overridden/[slug]'
,
routeKeys
:
{
slug
:
'slug'
,
},
},
],
],
redirects
:
[
redirects
:
[
{
{
...
@@ -2028,6 +2056,12 @@ const runTests = (isDev = false) => {
...
@@ -2028,6 +2056,12 @@ const runTests = (isDev = false) => {
regex
:
normalizeRegEx
(
'^
\\
/blog
\\
/about(?:
\\
/)?$'
),
regex
:
normalizeRegEx
(
'^
\\
/blog
\\
/about(?:
\\
/)?$'
),
source
:
'/blog/about'
,
source
:
'/blog/about'
,
},
},
{
destination
:
'/overridden'
,
regex
:
'^
\\
/overridden(?:
\\
/((?:[^
\\
/]+?)(?:
\\
/(?:[^
\\
/]+?))*))?(?:
\\
/)?$'
,
source
:
'/overridden/:path*'
,
},
],
],
fallback
:
[],
fallback
:
[],
},
},
...
@@ -2088,6 +2122,14 @@ const runTests = (isDev = false) => {
...
@@ -2088,6 +2122,14 @@ const runTests = (isDev = false) => {
slug
:
'slug'
,
slug
:
'slug'
,
},
},
},
},
{
namedRegex
:
'^/overridden/(?<slug>[^/]+?)(?:/)?$'
,
page
:
'/overridden/[slug]'
,
regex
:
'^
\\
/overridden
\\
/([^
\\
/]+?)(?:
\\
/)?$'
,
routeKeys
:
{
slug
:
'slug'
,
},
},
],
],
staticRoutes
:
[
staticRoutes
:
[
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment