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
6b50b132
Commit
6b50b132
authored
Dec 26, 2019
by
Joe Haddad
Committed by
JJ Kasper
Dec 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Boolean API Response (#9842)
parent
f89d55f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
api-utils.ts
packages/next/next-server/server/api-utils.ts
+5
-1
bool.js
test/integration/api-support/pages/api/bool.js
+3
-0
index.test.js
test/integration/api-support/test/index.test.js
+10
-0
No files found.
packages/next/next-server/server/api-utils.ts
View file @
6b50b132
...
...
@@ -204,7 +204,11 @@ export function sendData(res: NextApiResponse, body: any) {
let
str
=
body
// Stringify JSON body
if
(
typeof
body
===
'object'
||
typeof
body
===
'number'
)
{
if
(
typeof
body
===
'object'
||
typeof
body
===
'number'
||
typeof
body
===
'boolean'
)
{
str
=
JSON
.
stringify
(
body
)
res
.
setHeader
(
'Content-Type'
,
'application/json; charset=utf-8'
)
}
...
...
test/integration/api-support/pages/api/bool.js
0 → 100644
View file @
6b50b132
export
default
(
req
,
res
)
=>
{
res
.
json
(
true
)
}
test/integration/api-support/test/index.test.js
View file @
6b50b132
...
...
@@ -86,6 +86,16 @@ function runTests(dev = false) {
expect
(
data
).
toEqual
({})
})
it
(
'should support boolean for JSON in api page'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/api/bool'
,
null
,
{})
const
body
=
res
.
ok
?
await
res
.
json
()
:
null
expect
(
res
.
status
).
toBe
(
200
)
expect
(
res
.
headers
.
get
(
'content-type'
)).
toBe
(
'application/json; charset=utf-8'
)
expect
(
body
).
toBe
(
true
)
})
it
(
'should return error with invalid JSON'
,
async
()
=>
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/parse'
,
null
,
{
method
:
'POST'
,
...
...
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