mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 09:23:52 -05:00
Remove body-parser dependency (#7176)
This PR addresses issue #7158 by removing the body-parser dependency in favor of express.json() and other built-in middleware functionalities provided by Express.js.
This commit is contained in:
4
app.ts
4
app.ts
@@ -29,7 +29,6 @@ import process from 'process';
|
||||
import url from 'url';
|
||||
|
||||
import * as Sentry from '@sentry/node';
|
||||
import bodyParser from 'body-parser';
|
||||
import compression from 'compression';
|
||||
import express from 'express';
|
||||
import fs from 'fs-extra';
|
||||
@@ -525,6 +524,7 @@ async function main() {
|
||||
// Initialise express and then sentry. Sentry as early as possible to catch errors during startup.
|
||||
const webServer = express(),
|
||||
router = express.Router();
|
||||
|
||||
SetupSentry(aws.getConfig('sentryDsn'), ceProps, releaseBuildNumber, gitReleaseName, defArgs);
|
||||
|
||||
startWineInit();
|
||||
@@ -848,7 +848,7 @@ async function main() {
|
||||
),
|
||||
);
|
||||
})
|
||||
.use(bodyParser.json({limit: ceProps('bodyParserLimit', maxUploadSize)}))
|
||||
.use(express.json({limit: ceProps('bodyParserLimit', maxUploadSize)}))
|
||||
.use(siteTemplateController.createRouter())
|
||||
.use(sourceController.createRouter())
|
||||
.use(assemblyDocumentationController.createRouter())
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import bodyParser from 'body-parser';
|
||||
import express from 'express';
|
||||
import _ from 'underscore';
|
||||
|
||||
@@ -95,7 +94,7 @@ export class ApiHandler {
|
||||
.all(methodNotAllowed);
|
||||
|
||||
const maxUploadSize = ceProps('maxUploadSize', '1mb');
|
||||
const textParser = bodyParser.text({limit: ceProps('bodyParserLimit', maxUploadSize), type: () => true});
|
||||
const textParser = express.text({limit: ceProps('bodyParserLimit', maxUploadSize), type: () => true});
|
||||
|
||||
this.handle
|
||||
.route('/compiler/:compiler/compile')
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import bodyParser from 'body-parser';
|
||||
import express from 'express';
|
||||
|
||||
import {isString} from '../../shared/common-utils.js';
|
||||
@@ -48,7 +47,7 @@ export class NoScriptHandler {
|
||||
readonly defaultLanguage: string;
|
||||
readonly compileHandler: CompileHandler;
|
||||
|
||||
formDataParser: ReturnType<typeof bodyParser.urlencoded> | undefined;
|
||||
formDataParser: ReturnType<typeof express.urlencoded> | undefined;
|
||||
|
||||
/* the type for config makes the most sense to define in app.ts or api.ts */
|
||||
constructor(
|
||||
@@ -64,8 +63,7 @@ export class NoScriptHandler {
|
||||
}
|
||||
|
||||
InitializeRoutes(options: {limit: string}) {
|
||||
this.formDataParser = bodyParser.urlencoded({
|
||||
type: 'application/x-www-form-urlencoded',
|
||||
this.formDataParser = express.urlencoded({
|
||||
limit: options.limit,
|
||||
extended: false,
|
||||
});
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import bodyParser from 'body-parser';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import {beforeAll, describe, expect, it} from 'vitest';
|
||||
@@ -97,7 +96,7 @@ describe('API handling', () => {
|
||||
'default',
|
||||
{ceProps: (key, def) => def} as CompilationEnvironment,
|
||||
);
|
||||
app.use(bodyParser.json());
|
||||
app.use(express.json());
|
||||
app.use('/api', apiHandler.handle);
|
||||
apiHandler.setCompilers(compilers);
|
||||
apiHandler.setLanguages(languages);
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import bodyParser from 'body-parser';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import {beforeAll, describe, expect, it} from 'vitest';
|
||||
@@ -47,11 +46,11 @@ describe('Compiler tests', () => {
|
||||
const compilationEnvironment = makeCompilationEnvironment({languages});
|
||||
compileHandler = new CompileHandler(compilationEnvironment, fakeProps({}));
|
||||
|
||||
const textParser = bodyParser.text({type: () => true});
|
||||
const formParser = bodyParser.urlencoded({extended: false});
|
||||
const textParser = express.text({type: () => true});
|
||||
const formParser = express.urlencoded({extended: false});
|
||||
|
||||
app = express();
|
||||
app.use(bodyParser.json());
|
||||
app.use(express.json());
|
||||
|
||||
app.post('/noscript/compile', formParser, compileHandler.handle.bind(compileHandler));
|
||||
app.post('/:compiler/compile', textParser, compileHandler.handle.bind(compileHandler));
|
||||
|
||||
Reference in New Issue
Block a user