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
ab0a8647
Commit
ab0a8647
authored
Oct 26, 2019
by
Jan Potoms
Committed by
Tim Neutkens
Oct 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Take multiple values into account for the query (#9196)
* Take multiple values into account * make typescript happy
parent
20978af0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
api-utils.ts
packages/next/next-server/server/api-utils.ts
+9
-1
query.js
test/integration/api-support/pages/api/query.js
+3
-0
index.test.js
test/integration/api-support/test/index.test.js
+17
-0
No files found.
packages/next/next-server/server/api-utils.ts
View file @
ab0a8647
...
@@ -119,7 +119,15 @@ export function getQueryParser({ url }: IncomingMessage) {
...
@@ -119,7 +119,15 @@ export function getQueryParser({ url }: IncomingMessage) {
const
query
:
{
[
key
:
string
]:
string
|
string
[]
}
=
{}
const
query
:
{
[
key
:
string
]:
string
|
string
[]
}
=
{}
for
(
const
[
key
,
value
]
of
params
)
{
for
(
const
[
key
,
value
]
of
params
)
{
query
[
key
]
=
value
if
(
query
[
key
])
{
if
(
Array
.
isArray
(
query
[
key
]))
{
;(
query
[
key
]
as
string
[]).
push
(
value
)
}
else
{
query
[
key
]
=
[
query
[
key
],
value
]
}
}
else
{
query
[
key
]
=
value
}
}
}
return
query
return
query
...
...
test/integration/api-support/pages/api/query.js
0 → 100644
View file @
ab0a8647
export
default
(
req
,
res
)
=>
{
res
.
status
(
200
).
send
(
req
.
query
)
}
test/integration/api-support/test/index.test.js
View file @
ab0a8647
...
@@ -180,6 +180,23 @@ function runTests (serverless = false) {
...
@@ -180,6 +180,23 @@ function runTests (serverless = false) {
expect
(
data
).
toEqual
({
message
:
'Parsed body'
})
expect
(
data
).
toEqual
({
message
:
'Parsed body'
})
})
})
it
(
'should return empty query object'
,
async
()
=>
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/query'
,
null
,
{}).
then
(
res
=>
res
.
ok
&&
res
.
json
()
)
expect
(
data
).
toEqual
({})
})
it
(
'should parse query correctly'
,
async
()
=>
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/query?a=1&b=2&a=3'
,
null
,
{}
).
then
(
res
=>
res
.
ok
&&
res
.
json
())
expect
(
data
).
toEqual
({
a
:
[
'1'
,
'3'
],
b
:
'2'
})
})
it
(
'should return empty cookies object'
,
async
()
=>
{
it
(
'should return empty cookies object'
,
async
()
=>
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/cookies'
,
null
,
{}).
then
(
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/cookies'
,
null
,
{}).
then
(
res
=>
res
.
ok
&&
res
.
json
()
res
=>
res
.
ok
&&
res
.
json
()
...
...
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