Skip to content

Commit

Permalink
Functions: Handle query parameters correctly (#976)
Browse files Browse the repository at this point in the history
* Functions: Handle query parameters correctly

* Add test for query parsing for functions requests

* Formatting

* paramsToObject: Preseve multiple values of same key

* Simplify queryParams object creation

* Express: Use 'simple' query parser
  • Loading branch information
RaeesBhatti authored Jul 6, 2020
1 parent e9c3c6b commit 7ed8238
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utils/serve-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ function createFormSubmissionHandler(siteInfo) {

async function serveFunctions(dir, siteInfo = {}) {
const app = express()
app.set('query parser', 'simple')

app.use(
bodyParser.text({
Expand Down
6 changes: 6 additions & 0 deletions tests/dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ test('functions: not found', async t => {
t.is(response.status, 404)
})

test('functions: query parameters parsing', async t => {
const response = await fetch(`http://${host}/api/echo?category[SOMETHING][]=something`).then(r => r.json())

t.deepEqual(response.queryStringParameters, { 'category[SOMETHING][]': 'something' })
})

test('Netlify Forms support', async t => {
const form = new FormData()
form.append('some', 'thing')
Expand Down

0 comments on commit 7ed8238

Please sign in to comment.