Merge pull request #33361 from overleaf/copilot/remove-direct-use-of-body-parser

Remove direct use of body-parser in favour of express built-ins

GitOrigin-RevId: 656c5f216daf68e86d53ae07d272e080bd5ab27f
This commit is contained in:
Lucie Germain
2026-09-17 11:14:46 +00:00
committed by Copybot
parent 6be5db7667
commit 210ced0d31
25 changed files with 24 additions and 65 deletions
-1
View File
@@ -22,7 +22,6 @@
"@overleaf/promise-utils": "*",
"@overleaf/settings": "*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"exegesis-express": "4.0.0",
"express": "4.22.1",
"mongodb": "6.12.0"
+5 -6
View File
@@ -15,7 +15,6 @@ import ProjectPersistenceManager from './app/js/ProjectPersistenceManager.js'
import OutputCacheManager from './app/js/OutputCacheManager.js'
import express from 'express'
import bodyParser from 'body-parser'
import net from 'node:net'
import os from 'node:os'
@@ -73,7 +72,7 @@ app.param('build_id', function (req, res, next, buildId) {
app.post(
'/project/:project_id/compile',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
CompileController.compile
)
app.post('/project/:project_id/compile/stop', CompileController.stopCompile)
@@ -88,7 +87,7 @@ app.post('/project/:project_id/status', CompileController.status)
// Per-user containers
app.post(
'/project/:project_id/user/:user_id/compile',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
CompileController.compile
)
app.post(
@@ -113,14 +112,14 @@ app.get(
// This needs to be before GET /project/:project_id/build/:build_id/output/*
app.get(
'/project/:project_id/build/:build_id/output/output.zip',
bodyParser.json(),
express.json(),
OutputController.createOutputZip
)
// This needs to be before GET /project/:project_id/user/:user_id/build/:build_id/output/*
app.get(
'/project/:project_id/user/:user_id/build/:build_id/output/output.zip',
bodyParser.json(),
express.json(),
OutputController.createOutputZip
)
@@ -142,7 +141,7 @@ app.post(
)
app.post(
'/project/:project_id/user/:user_id/download/project-to-document',
bodyParser.json({ limit: Settings.compileSizeLimit }),
express.json({ limit: Settings.compileSizeLimit }),
ConversionController.convertProjectToDocument
)
app.post(
-1
View File
@@ -26,7 +26,6 @@
"@overleaf/validation-tools": "workspace:*",
"archiver": "5.3.2",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"dockerode": "^4.0.9",
"express": "4.22.1",
+2 -3
View File
@@ -6,7 +6,6 @@ import Metrics from '@overleaf/metrics'
import Settings from '@overleaf/settings'
import logger from '@overleaf/logger'
import express from 'express'
import bodyParser from 'body-parser'
import { handleValidationError } from '@overleaf/validation-tools'
import mongodb from './app/js/mongodb.js'
import Errors from './app/js/Errors.js'
@@ -69,12 +68,12 @@ app.get('/project/:project_id/doc/:doc_id/peek', HttpController.peekDoc)
// Add 64kb overhead for the JSON encoding, and double the size to allow for ranges in the json payload
app.post(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: Settings.maxJsonRequestSize }),
express.json({ limit: Settings.maxJsonRequestSize }),
HttpController.updateDoc
)
app.patch(
'/project/:project_id/doc/:doc_id',
bodyParser.json(),
express.json(),
HttpController.patchDoc
)
app.delete('/project/:project_id/doc/:doc_id', (req, res) => {
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/stream-utils": "^0.1.0",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"lodash": "^4.18.1",
+1 -3
View File
@@ -17,13 +17,11 @@ const HttpController = require('./app/js/HttpController')
const mongodb = require('./app/js/mongodb')
const async = require('async')
const bodyParser = require('body-parser')
Metrics.event_loop.monitor(logger, 100)
Metrics.open_sockets.monitor()
const app = express()
app.use(bodyParser.json({ limit: Settings.maxJsonRequestSize }))
app.use(express.json({ limit: Settings.maxJsonRequestSize }))
Metrics.injectMetricsRoute(app)
DispatchManager.createAndStartDispatchers(Settings.dispatcherCount)
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/settings": "workspace:*",
"@types/chai-as-promised": "^7.1.8",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bull": "^3.18.0",
"bunyan": "^1.8.15",
"diff-match-patch": "overleaf/diff-match-patch#89805f9c671a77a263fc53461acd62aa7498f688",
@@ -1,5 +1,4 @@
const express = require('express')
const bodyParser = require('body-parser')
const { expressify } = require('@overleaf/promise-utils')
const app = express()
const MAX_REQUEST_SIZE = 2 * (2 * 1024 * 1024 + 64 * 1024)
@@ -79,7 +78,7 @@ const MockDocstoreApi = {
app.patch(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
express.json({ limit: MAX_REQUEST_SIZE }),
expressify(async (req, res) => {
try {
await MockDocstoreApi.patchDocument(
@@ -2,7 +2,6 @@ let MockWebApi
const basicAuth = require('basic-auth')
const tsscmp = require('tsscmp')
const express = require('express')
const bodyParser = require('body-parser')
const { expressify } = require('@overleaf/promise-utils')
const Settings = require('@overleaf/settings')
const app = express()
@@ -113,7 +112,7 @@ module.exports = MockWebApi = {
app.post(
'/project/:project_id/doc/:doc_id',
bodyParser.json({ limit: MAX_REQUEST_SIZE }),
express.json({ limit: MAX_REQUEST_SIZE }),
expressify(async (req, res, next) => {
await this.setDocumentController(req, res, next)
})
-1
View File
@@ -25,7 +25,6 @@
"@overleaf/object-persistor": "workspace:*",
"@overleaf/settings": "workspace:*",
"@overleaf/stream-utils": "^0.1.0",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"glob": "^12.0.0",
+2 -3
View File
@@ -12,7 +12,6 @@ const helmet = require('helmet')
const HTTPStatus = require('http-status')
const logger = require('@overleaf/logger')
const Metrics = require('@overleaf/metrics')
const bodyParser = require('body-parser')
const security = require('./api/middleware/security')
const healthChecks = require('./api/controllers/health_checks')
const { mongodb, loadGlobalBlobs } = require('./storage')
@@ -37,9 +36,9 @@ Metrics.leaked_sockets.monitor(logger)
// We may have fairly large JSON bodies when receiving large Changes. Clients
// may have to handle 413 status codes and try creating files instead of sending
// text content in changes.
app.use(bodyParser.json({ limit: '12MB' }))
app.use(express.json({ limit: '12MB' }))
app.use(
bodyParser.urlencoded({
express.urlencoded({
extended: false,
})
)
-1
View File
@@ -21,7 +21,6 @@
"archiver": "^5.3.0",
"basic-auth": "^2.0.1",
"bluebird": "^3.7.2",
"body-parser": "1.20.4",
"bull": "^4.16.5",
"bunyan": "^1.8.12",
"check-types": "^11.1.2",
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/settings": "workspace:*",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"express": "4.22.1",
"mongodb-legacy": "6.1.3",
+2 -3
View File
@@ -2,7 +2,6 @@ import Metrics from '@overleaf/metrics'
import logger from '@overleaf/logger'
import OError from '@overleaf/o-error'
import express from 'express'
import bodyParser from 'body-parser'
import * as Errors from './Errors.js'
import * as Router from './Router.js'
import { handleValidationError } from '@overleaf/validation-tools'
@@ -40,8 +39,8 @@ HistoryLogger.addSerializers({
})
export const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(Metrics.http.monitor(logger))
Router.initialize(app)
Metrics.injectMetricsRoute(app)
-1
View File
@@ -27,7 +27,6 @@
"@overleaf/stream-utils": "workspace:*",
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"diff-match-patch": "overleaf/diff-match-patch#89805f9c671a77a263fc53461acd62aa7498f688",
"express": "4.22.1",
+2 -2
View File
@@ -1,11 +1,11 @@
import metrics from '@overleaf/metrics'
import logger from '@overleaf/logger'
import settings from '@overleaf/settings'
import express from 'express'
import WebsocketController from './WebsocketController.js'
import HttpController from './HttpController.js'
import HttpApiController from './HttpApiController.js'
import WebsocketAddressManager from './WebsocketAddressManager.js'
import bodyParser from 'body-parser'
import base64id from 'base64id'
import Errors from './Errors.js'
import { z, zz } from '@overleaf/validation-tools'
@@ -157,7 +157,7 @@ export default Router = {
app.post(
'/project/:project_id/message/:message',
bodyParser.json({ limit: '5mb' }),
express.json({ limit: '5mb' }),
HttpApiController.sendMessage
)
app.get(
-1
View File
@@ -26,7 +26,6 @@
"@overleaf/validation-tools": "workspace:*",
"async": "^3.2.5",
"base64id": "0.1.0",
"body-parser": "1.20.4",
"bunyan": "^1.8.15",
"connect-redis": "^6.1.3",
"cookie-parser": "^1.4.6",
@@ -11,7 +11,6 @@
*/
import sinon from 'sinon'
import express from 'express'
import bodyParser from 'body-parser'
let MockWebServer
@@ -90,7 +89,7 @@ export default MockWebServer = {
return callback()
}
const app = express()
app.use(bodyParser.json())
app.use(express.json())
app.post('/project/:project_id/join', MockWebServer.joinProjectRequest)
return app
.listen(3000, error => {
@@ -1,4 +1,4 @@
import bodyParser from 'body-parser'
import express from 'express'
import HttpErrorHandler from '../Features/Errors/HttpErrorHandler.mjs'
function isBodyParserError(nextArg) {
@@ -13,7 +13,7 @@ function isBodyParserError(nextArg) {
}
const wrapBodyParser = method => opts => {
const middleware = bodyParser[method](opts)
const middleware = express[method](opts)
return function bodyParser(req, res, next) {
middleware(req, res, nextArg => {
if (isBodyParserError(nextArg)) {
-1
View File
@@ -114,7 +114,6 @@
"base-x": "^4.0.1",
"basic-auth": "^2.0.1",
"bcrypt": "^6.0.0",
"body-parser": "1.20.4",
"bowser": "^2.11.0",
"bull": "^3.18.0",
"bunyan": "^1.8.15",
@@ -1,6 +1,5 @@
import OError from '@overleaf/o-error'
import express from 'express'
import bodyParser from 'body-parser'
/**
* Abstract class for running a mock API via Express. Handles setting up of
@@ -49,8 +48,8 @@ class AbstractMockApi {
this.debug = debug
this.port = port
this.app = express()
this.app.use(bodyParser.json())
this.app.use(bodyParser.urlencoded({ extended: true }))
this.app.use(express.json())
this.app.use(express.urlencoded({ extended: true }))
}
/**