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
850a552c
Commit
850a552c
authored
Dec 04, 2023
by
Zack Tanner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix nextConfig headers not applying to static resources with i18n
parent
708f85b9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
3 deletions
+79
-3
load-custom-routes.ts
packages/next/src/lib/load-custom-routes.ts
+4
-3
next.config.js
test/integration/custom-routes-i18n/next.config.js
+13
-0
index.test.js
test/integration/custom-routes-i18n/test/index.test.js
+26
-0
next.config.js
test/integration/custom-routes/next.config.js
+9
-0
index.test.js
test/integration/custom-routes/test/index.test.js
+27
-0
No files found.
packages/next/src/lib/load-custom-routes.ts
View file @
850a552c
...
...
@@ -547,9 +547,10 @@ function processRoutes<T>(
})
}
r
.
source
=
`/:nextInternalLocale(
${
config
.
i18n
.
locales
.
map
((
locale
:
string
)
=>
escapeStringRegexp
(
locale
))
.
join
(
'|'
)}
)
${
const
locales
=
config
.
i18n
.
locales
.
map
(
escapeStringRegexp
).
join
(
'|'
)
// locale is intentionally marked optional here so that custom route headers
// are applied to static resources (which don't have a locale prefix)
r
.
source
=
`/:nextInternalLocale(
${
locales
}
)?
${
r
.
source
===
'/'
&&
!
config
.
trailingSlash
?
''
:
r
.
source
}
`
...
...
test/integration/custom-routes-i18n/next.config.js
View file @
850a552c
...
...
@@ -81,4 +81,17 @@ module.exports = {
},
]
},
async
headers
()
{
return
[
{
source
:
'/:path*'
,
headers
:
[
{
key
:
'X-Custom-Header'
,
value
:
'my custom header value'
,
},
],
},
]
},
}
test/integration/custom-routes-i18n/test/index.test.js
View file @
850a552c
...
...
@@ -145,6 +145,32 @@ const runTests = () => {
expect
(
await
browser
.
eval
(
'window.beforeNav'
)).
toBe
(
1
)
}
})
it
(
'should apply custom headers to all responses'
,
async
()
=>
{
const
staticHeaders
=
[]
const
otherHeaders
=
[]
const
browser
=
await
webdriver
(
appPort
,
'/'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'response'
,
(
response
)
=>
{
const
url
=
new
URL
(
response
.
url
())
if
(
url
.
pathname
.
includes
(
'_next/static/'
))
{
staticHeaders
.
push
(
response
.
headers
())
}
else
{
otherHeaders
.
push
(
response
.
headers
())
}
})
},
})
await
check
(()
=>
browser
.
elementById
(
'links'
).
text
(),
'Links'
)
expect
(
staticHeaders
.
length
).
toBeGreaterThan
(
0
)
expect
(
otherHeaders
.
length
).
toBeGreaterThan
(
0
)
expect
(
[...
staticHeaders
,
...
otherHeaders
].
every
(
(
headers
)
=>
headers
[
'x-custom-header'
]
===
'my custom header value'
)
).
toBe
(
true
)
})
}
describe
(
'Custom routes i18n'
,
()
=>
{
...
...
test/integration/custom-routes/next.config.js
View file @
850a552c
...
...
@@ -755,6 +755,15 @@ module.exports = {
},
],
},
{
source
:
'/:path*'
,
headers
:
[
{
key
:
'X-Global-Custom-Header'
,
value
:
'my custom header value'
,
},
],
},
]
},
}
test/integration/custom-routes/test/index.test.js
View file @
850a552c
...
...
@@ -1475,6 +1475,33 @@ const runTests = (isDev = false) => {
expect
(
res2
.
headers
.
get
(
'x-is-host'
)).
toBe
(
null
)
})
it
(
'should apply custom headers to all responses'
,
async
()
=>
{
const
staticHeaders
=
[]
const
otherHeaders
=
[]
const
browser
=
await
webdriver
(
appPort
,
'/nav'
,
{
beforePageLoad
:
(
page
)
=>
{
page
.
on
(
'response'
,
(
response
)
=>
{
const
url
=
new
URL
(
response
.
url
())
if
(
url
.
pathname
.
includes
(
'_next/static/'
))
{
staticHeaders
.
push
(
response
.
headers
())
}
else
{
otherHeaders
.
push
(
response
.
headers
())
}
})
},
})
await
check
(()
=>
browser
.
elementById
(
'nav'
).
text
(),
'Nav'
)
expect
(
staticHeaders
.
length
).
toBeGreaterThan
(
0
)
expect
(
otherHeaders
.
length
).
toBeGreaterThan
(
0
)
expect
(
[...
staticHeaders
,
...
otherHeaders
].
every
(
(
headers
)
=>
headers
[
'x-global-custom-header'
]
===
'my custom header value'
)
).
toBe
(
true
)
})
if
(
!
isDev
)
{
it
(
'should output routes-manifest successfully'
,
async
()
=>
{
const
manifest
=
await
fs
.
readJSON
(
...
...
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