From 7fcf3a7084bbc078d3d11bc43433e29b69d95970 Mon Sep 17 00:00:00 2001 From: Marshal Date: Tue, 28 Jul 2026 06:33:26 +0000 Subject: [PATCH] update body-parser implementation to use Nest's API and improve dependency handling --- apps/edr-freight-api/src/main.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/edr-freight-api/src/main.ts b/apps/edr-freight-api/src/main.ts index 20c21b984..9efc7fa21 100644 --- a/apps/edr-freight-api/src/main.ts +++ b/apps/edr-freight-api/src/main.ts @@ -2,7 +2,7 @@ import "reflect-metadata"; import * as dotenv from "dotenv"; dotenv.config(); import { NestFactory } from "@nestjs/core"; -import { json, urlencoded } from "express"; +import type { NestExpressApplication } from "@nestjs/platform-express"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; import { HttpExceptionFilter, @@ -21,10 +21,16 @@ import { AppModule } from "./app.module"; const JSON_BODY_LIMIT = '20mb'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule); - app.use(json({ limit: JSON_BODY_LIMIT })); - app.use(urlencoded({ limit: JSON_BODY_LIMIT, extended: true })); + // Nest's own body-parser API, NOT `app.use(json(...))` from express: express + // is not a declared dependency of this app (it arrives under + // @nestjs/platform-express), so importing it directly resolved only through + // pnpm's hoisted dev store and died as MODULE_NOT_FOUND in the production + // image, where `pnpm deploy --prod` installs declared dependencies only. + // This also RECONFIGURES the default parsers rather than racing them. + app.useBodyParser('json', { limit: JSON_BODY_LIMIT }); + app.useBodyParser('urlencoded', { limit: JSON_BODY_LIMIT, extended: true }); // Dev CORS: reflect any localhost origin and allow credentials so the // freight portal (5173), passenger portal (5174), backoffices (5183/5184)