Mario Schrattenecker
AAlokai
•Created by Mario Schrattenecker on 6/6/2023 in #🙋|general-help
Server Middleware - Express.JS body size limit
Hello,
We are currently using VSF 2.5 (which as per package-lock.json uses express 4.17.1) to integrate with our product.
In doing so I encountered an issue with the body size limit for a post request used to add a product of one of our customers to a database that should hold that information.
The error I am receiving when I try to send the JSON body to our API tells me the following:
Headers - General
Staus Code: 413 RuntimeError
Headers - Request Headers
Content-Length: 115309
Judging by the fact that the message is "request entity too large" and the expressjs documentation telling me, that the standard body size limit for express.json() is "100kb",
it leads me to believe that the issue is obviously the content size of about 115kb here.
The question/-s I find myself with now is, where do I tell VSF to use for example "200kb" as the limit for its Server Middleware? Or do I need to do that with an extension?
Reading the documentation I found this article in the docs: https://docs.vuestorefront.io/v2/architecture/server-middleware.html
This mentions in its "Configuration" section the "integration interface". So checking that out, its "extensions" seem the way to handle that.
To be more precise the optional "extendApp" function seems to be what I should use for that? Since it accepts an "app: Express" and a "configuration".
I checked the code in my node_modules folder which leads me to the createServer.ts file in "@vue-storefront/middleware/src"
But after all this I am still not sure, how to increase the limit of the express.json() for it.
The thing to do in expressjs would be "app.use(express.json({ limit: "200kb" })).
Though where do I set this so it uses it?
I hope somebody can give a lead into the right direction or tell me if I am on the wrong track.
32 replies