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
7af04db4
Unverified
Commit
7af04db4
authored
Apr 09, 2020
by
JJ Kasper
Committed by
GitHub
Apr 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix just headers not being applied in dev mode (#11755)
parent
fa167e33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
2 deletions
+106
-2
next-dev-server.ts
packages/next/server/next-dev-server.ts
+2
-2
index.test.js
test/integration/custom-routes/test/index.test.js
+104
-0
No files found.
packages/next/server/next-dev-server.ts
View file @
7af04db4
...
...
@@ -237,9 +237,9 @@ export default class DevServer extends Server {
await
this
.
loadCustomRoutes
()
if
(
this
.
customRoutes
)
{
const
{
redirects
,
rewrites
}
=
this
.
customRoutes
const
{
redirects
,
rewrites
,
headers
}
=
this
.
customRoutes
if
(
redirects
.
length
||
rewrites
.
length
)
{
if
(
redirects
.
length
||
rewrites
.
length
||
headers
.
length
)
{
this
.
router
=
new
Router
(
this
.
generateRoutes
())
}
}
...
...
test/integration/custom-routes/test/index.test.js
View file @
7af04db4
...
...
@@ -885,4 +885,108 @@ describe('Custom routes', () => {
})
})
})
describe
(
'should load custom routes when only one type is used'
,
()
=>
{
const
runSoloTests
=
isDev
=>
{
const
buildAndStart
=
async
()
=>
{
if
(
isDev
)
{
appPort
=
await
findPort
()
app
=
await
launchApp
(
appDir
,
appPort
)
}
else
{
const
{
code
}
=
await
nextBuild
(
appDir
)
if
(
code
!==
0
)
throw
new
Error
(
`failed to build, got code
${
code
}
`
)
appPort
=
await
findPort
()
app
=
await
nextStart
(
appDir
,
appPort
)
}
}
it
(
'should work with just headers'
,
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfigPath
,
'utf8'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
.
replace
(
/
(
async
(?:
redirects|rewrites
))
/g
,
'$1s'
)
)
await
buildAndStart
()
const
res
=
await
fetchViaHTTP
(
appPort
,
'/add-header'
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/docs/github'
,
undefined
,
{
redirect
:
'manual'
,
})
const
res3
=
await
fetchViaHTTP
(
appPort
,
'/hello-world'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
)
await
killApp
(
app
)
expect
(
res
.
headers
.
get
(
'x-custom-header'
)).
toBe
(
'hello world'
)
expect
(
res
.
headers
.
get
(
'x-another-header'
)).
toBe
(
'hello again'
)
expect
(
res2
.
status
).
toBe
(
404
)
expect
(
res3
.
status
).
toBe
(
404
)
})
it
(
'should work with just rewrites'
,
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfigPath
,
'utf8'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
.
replace
(
/
(
async
(?:
redirects|headers
))
/g
,
'$1s'
)
)
await
buildAndStart
()
const
res
=
await
fetchViaHTTP
(
appPort
,
'/add-header'
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/docs/github'
,
undefined
,
{
redirect
:
'manual'
,
})
const
res3
=
await
fetchViaHTTP
(
appPort
,
'/hello-world'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
)
await
killApp
(
app
)
expect
(
res
.
headers
.
get
(
'x-custom-header'
)).
toBeFalsy
()
expect
(
res
.
headers
.
get
(
'x-another-header'
)).
toBeFalsy
()
expect
(
res2
.
status
).
toBe
(
404
)
expect
(
res3
.
status
).
toBe
(
200
)
expect
(
await
res3
.
text
()).
toContain
(
'hello world!'
)
})
it
(
'should work with just redirects'
,
async
()
=>
{
nextConfigContent
=
await
fs
.
readFile
(
nextConfigPath
,
'utf8'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
.
replace
(
/
(
async
(?:
rewrites|headers
))
/g
,
'$1s'
)
)
await
buildAndStart
()
const
res
=
await
fetchViaHTTP
(
appPort
,
'/add-header'
)
const
res2
=
await
fetchViaHTTP
(
appPort
,
'/docs/github'
,
undefined
,
{
redirect
:
'manual'
,
})
const
res3
=
await
fetchViaHTTP
(
appPort
,
'/hello world'
)
await
fs
.
writeFile
(
nextConfigPath
,
nextConfigContent
)
await
killApp
(
app
)
expect
(
res
.
headers
.
get
(
'x-custom-header'
)).
toBeFalsy
()
expect
(
res
.
headers
.
get
(
'x-another-header'
)).
toBeFalsy
()
const
{
pathname
}
=
url
.
parse
(
res2
.
headers
.
get
(
'location'
))
expect
(
res2
.
status
).
toBe
(
301
)
expect
(
pathname
).
toBe
(
'/docs/v2/advanced/now-for-github'
)
expect
(
res3
.
status
).
toBe
(
404
)
})
}
describe
(
'dev mode'
,
()
=>
{
runSoloTests
(
true
)
})
describe
(
'production mode'
,
()
=>
{
runSoloTests
()
})
})
})
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