Skip to content

Commit

Permalink
Fixed request entity too large
Browse files Browse the repository at this point in the history
- removed body-parser and use express middlewares instead
- removed duplicit middlewares
- set limit to 50mb for middlewares

Fixes bug-hunters#53

Signed-off-by: Martin Sunal <[email protected]>
  • Loading branch information
MartinSunal committed Aug 16, 2022
1 parent 1b4290f commit 4745208
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
],
"dependencies": {
"async": "^3.2.4",
"body-parser": "1.19.0",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"debug": "^4.1.1",
Expand Down
11 changes: 4 additions & 7 deletions src/middleware/express.app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import * as express from 'express';
import cookieParser = require('cookie-parser');
import bodyParser = require('body-parser');
import cors = require('cors');
import { SwaggerUI } from './swagger.ui';
import { SwaggerRouter } from './swagger.router';
Expand Down Expand Up @@ -32,14 +31,12 @@ export class ExpressAppConfig {
const spec = fs.readFileSync(definitionPath, 'utf8');
const swaggerDoc = jsyaml.safeLoad(spec);

this.app.use(bodyParser.urlencoded());
this.app.use(bodyParser.text());
this.app.use(bodyParser.json());
this.app.use(bodyParser.raw({ type: 'application/pdf' }));
this.app.use(express.urlencoded({ limit: '50mb', extended: true }));
this.app.use(express.text({ limit: '50mb' }));
this.app.use(express.json({ limit: '50mb' }));
this.app.use(express.raw({ limit: '50mb', type: 'application/pdf' }));

this.app.use(this.configureLogger(appOptions.logging));
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: false }));
this.app.use(cookieParser());

const swaggerUi = new SwaggerUI(swaggerDoc, appOptions.swaggerUI);
Expand Down

0 comments on commit 4745208

Please sign in to comment.