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
1c7b2603
Commit
1c7b2603
authored
Jul 06, 2017
by
Arunoda Susiripala
Committed by
GitHub
Jul 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block special pages from the public. (#2479)
Otherwise, users could invoke 500 errors.
parent
ace1939c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
index.js
server/index.js
+9
-0
index.test.js
test/integration/production/test/index.test.js
+8
-0
No files found.
server/index.js
View file @
1c7b2603
...
@@ -24,6 +24,11 @@ const internalPrefixes = [
...
@@ -24,6 +24,11 @@ const internalPrefixes = [
/^
\/
static
\/
/
/^
\/
static
\/
/
]
]
const
blockedPages
=
{
'/_document'
:
true
,
'/_error'
:
true
}
export
default
class
Server
{
export
default
class
Server
{
constructor
({
dir
=
'.'
,
dev
=
false
,
staticMarkup
=
false
,
quiet
=
false
,
conf
=
null
}
=
{})
{
constructor
({
dir
=
'.'
,
dev
=
false
,
staticMarkup
=
false
,
quiet
=
false
,
conf
=
null
}
=
{})
{
this
.
dir
=
resolve
(
dir
)
this
.
dir
=
resolve
(
dir
)
...
@@ -251,6 +256,10 @@ export default class Server {
...
@@ -251,6 +256,10 @@ export default class Server {
return
this
.
handleRequest
(
req
,
res
,
parsedUrl
)
return
this
.
handleRequest
(
req
,
res
,
parsedUrl
)
}
}
if
(
blockedPages
[
pathname
])
{
return
await
this
.
render404
(
req
,
res
,
parsedUrl
)
}
if
(
this
.
config
.
poweredByHeader
)
{
if
(
this
.
config
.
poweredByHeader
)
{
res
.
setHeader
(
'X-Powered-By'
,
`Next.js
${
pkg
.
version
}
`
)
res
.
setHeader
(
'X-Powered-By'
,
`Next.js
${
pkg
.
version
}
`
)
}
}
...
...
test/integration/production/test/index.test.js
View file @
1c7b2603
...
@@ -49,6 +49,14 @@ describe('Production Usage', () => {
...
@@ -49,6 +49,14 @@ describe('Production Usage', () => {
const
res2
=
await
fetch
(
url
,
{
headers
})
const
res2
=
await
fetch
(
url
,
{
headers
})
expect
(
res2
.
status
).
toBe
(
304
)
expect
(
res2
.
status
).
toBe
(
304
)
})
})
it
(
'should block special pages'
,
async
()
=>
{
const
urls
=
[
'/_document'
,
'/_error'
]
for
(
const
url
of
urls
)
{
const
html
=
await
renderViaHTTP
(
appPort
,
url
)
expect
(
html
).
toMatch
(
/404/
)
}
})
})
})
describe
(
'With navigation'
,
()
=>
{
describe
(
'With navigation'
,
()
=>
{
...
...
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