fix(medusa): Query parser issues with large array (#4213)

* fix(medusa): Query parser issues with large array

* Create little-weeks-exercise.md

* add integration tests
This commit is contained in:
Adrien de Peretti
2023-06-14 13:36:04 +02:00
committed by GitHub
parent 5eae7f03ef
commit 02b1bd07cd
5 changed files with 85 additions and 36 deletions
+1
View File
@@ -83,6 +83,7 @@
"passport-http-bearer": "^1.0.1",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"qs": "^6.11.2",
"randomatic": "^3.1.1",
"redis": "^3.0.2",
"reflect-metadata": "^0.1.13",
+13
View File
@@ -1,4 +1,5 @@
import { Express } from "express"
import qs from "qs"
import bodyParser from "body-parser"
import routes from "../api"
import { AwilixContainer } from "awilix"
@@ -11,6 +12,18 @@ type Options = {
}
export default async ({ app, container, configModule }: Options) => {
// This is a workaround for the issue described here: https://github.com/expressjs/express/issues/3454
// We parse the url and get the qs to be parsed and override the query prop from the request
app.use(function (req, res, next) {
const parsedUrl = req.url.split("?")
parsedUrl.shift()
const queryParamsStr = parsedUrl.join("?")
if (queryParamsStr) {
req.query = qs.parse(queryParamsStr, { arrayLimit: Infinity })
}
next()
})
app.use(bodyParser.json())
app.use("/", routes(container, configModule.projectConfig))