From ae05f33f1ae173c8bd6ac19b61b56f9f736edc63 Mon Sep 17 00:00:00 2001 From: dimden <26517362+dimdenGD@users.noreply.github.com> Date: Sat, 9 Nov 2024 12:26:01 +0200 Subject: [PATCH] add large body test --- tests/tests/middlewares/body-json-large.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/tests/middlewares/body-json-large.js diff --git a/tests/tests/middlewares/body-json-large.js b/tests/tests/middlewares/body-json-large.js new file mode 100644 index 0000000..0276d46 --- /dev/null +++ b/tests/tests/middlewares/body-json-large.js @@ -0,0 +1,29 @@ +// must support json body parser with large body + +const express = require("express"); +const bodyParser = require("body-parser"); + +const app = express(); + +app.use(bodyParser.json({ limit: '10mb' })); + +app.post('/abc', (req, res) => { + res.send({ result: req.body?.items?.length }); +}); + +app.listen(13333, async () => { + console.log('Server is running on port 13333'); + + const response = await fetch('http://localhost:13333/abc', { + method: 'POST', + body: JSON.stringify({ items: Array(100_000).fill().map((_, i) => i + 1) }), + headers: { + 'Content-Type': 'application/json' + } + }); + const text = await response.text(); + console.log(text); + + process.exit(0); + +}); \ No newline at end of file