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
8d304ed7
Unverified
Commit
8d304ed7
authored
Sep 07, 2018
by
Tim Neutkens
Committed by
GitHub
Sep 07, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make non-existent routes under `/_next` return 404 (#5120)
Fixes #5114 Also adds a test for it.
parent
7c0de2c3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
index.js
server/index.js
+5
-0
rendering.js
test/integration/basic/test/rendering.js
+6
-1
index.test.js
test/integration/production/test/index.test.js
+6
-0
No files found.
server/index.js
View file @
8d304ed7
...
@@ -180,6 +180,11 @@ export default class Server {
...
@@ -180,6 +180,11 @@ export default class Server {
}
}
}
}
// This path is needed because `render()` does a check for `/_next` and the calls the routing again
routes
[
'/_next/:path*'
]
=
async
(
req
,
res
,
params
,
parsedUrl
)
=>
{
await
this
.
render404
(
req
,
res
,
parsedUrl
)
}
// It's very important keep this route's param optional.
// It's very important keep this route's param optional.
// (but it should support as many as params, seperated by '/')
// (but it should support as many as params, seperated by '/')
// Othewise this will lead to a pretty simple DOS attack.
// Othewise this will lead to a pretty simple DOS attack.
...
...
test/integration/basic/test/rendering.js
View file @
8d304ed7
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
cheerio
from
'cheerio'
import
cheerio
from
'cheerio'
export
default
function
({
app
},
suiteName
,
render
,
fetch
)
{
export
default
function
({
app
},
suiteName
,
render
,
fetch
,
appPort
)
{
async
function
get
$
(
path
,
query
)
{
async
function
get
$
(
path
,
query
)
{
const
html
=
await
render
(
path
,
query
)
const
html
=
await
render
(
path
,
query
)
return
cheerio
.
load
(
html
)
return
cheerio
.
load
(
html
)
...
@@ -123,6 +123,11 @@ export default function ({ app }, suiteName, render, fetch) {
...
@@ -123,6 +123,11 @@ export default function ({ app }, suiteName, render, fetch) {
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toMatch
(
'text/html; charset=iso-8859-2'
)
expect
(
res
.
headers
.
get
(
'Content-Type'
)).
toMatch
(
'text/html; charset=iso-8859-2'
)
})
})
test
(
'should render 404 for _next routes that do not exist'
,
async
()
=>
{
const
res
=
await
fetch
(
'/_next/abcdef'
)
expect
(
res
.
status
).
toBe
(
404
)
})
test
(
'allows to import .json files'
,
async
()
=>
{
test
(
'allows to import .json files'
,
async
()
=>
{
const
html
=
await
render
(
'/json'
)
const
html
=
await
render
(
'/json'
)
expect
(
html
.
includes
(
'Zeit'
)).
toBeTruthy
()
expect
(
html
.
includes
(
'Zeit'
)).
toBeTruthy
()
...
...
test/integration/production/test/index.test.js
View file @
8d304ed7
...
@@ -54,6 +54,12 @@ describe('Production Usage', () => {
...
@@ -54,6 +54,12 @@ describe('Production Usage', () => {
expect
(
res2
.
status
).
toBe
(
304
)
expect
(
res2
.
status
).
toBe
(
304
)
})
})
it
(
'should render 404 for _next routes that do not exist'
,
async
()
=>
{
const
url
=
`http://localhost:
${
appPort
}
/_next/abcdef`
const
res
=
await
fetch
(
url
)
expect
(
res
.
status
).
toBe
(
404
)
})
it
(
'should set Cache-Control header'
,
async
()
=>
{
it
(
'should set Cache-Control header'
,
async
()
=>
{
const
buildId
=
readFileSync
(
join
(
__dirname
,
'../.next/BUILD_ID'
),
'utf8'
)
const
buildId
=
readFileSync
(
join
(
__dirname
,
'../.next/BUILD_ID'
),
'utf8'
)
const
buildManifest
=
require
(
join
(
'../.next'
,
BUILD_MANIFEST
))
const
buildManifest
=
require
(
join
(
'../.next'
,
BUILD_MANIFEST
))
...
...
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