From d4442060e481ea59acfc1eee21729f4040a4a965 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Wed, 13 Mar 2024 14:49:53 +0100 Subject: [PATCH] add postRequestPayloadSize on dev and fix type --- src/cli/commands.ts | 4 ++++ src/cli/facade/dev.ts | 3 +++ src/registry/middleware/index.ts | 6 ++++-- src/types.ts | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cli/commands.ts b/src/cli/commands.ts index 72b556b36..f00d89740 100644 --- a/src/cli/commands.ts +++ b/src/cli/commands.ts @@ -33,6 +33,10 @@ export default { 'Enable hot reloading. Note: when hot reloading is set to true, each request to the component will make the registry to create a new instance for the javascript closures to be loaded, while when false the instance will be recycled between components executions', default: true }, + postRequestPayloadSize: { + description: 'Maximum payload size for post requests', + default: '100kb' + }, verbose: { boolean: true, description: 'Verbosity', diff --git a/src/cli/facade/dev.ts b/src/cli/facade/dev.ts index 6d6b1cc37..d484fc44b 100644 --- a/src/cli/facade/dev.ts +++ b/src/cli/facade/dev.ts @@ -30,6 +30,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) => baseUrl: string; fallbackRegistryUrl: string; hotReloading?: boolean; + postRequestPayloadSize?: string; components?: string[]; watch?: boolean; verbose?: boolean; @@ -43,6 +44,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) => typeof opts.hotReloading === 'undefined' ? true : opts.hotReloading; const optWatch = typeof opts.watch === 'undefined' ? true : opts.watch; let packaging = false; + const postRequestPayloadSize = opts.postRequestPayloadSize || '100kb'; const watchForChanges = function ( { @@ -176,6 +178,7 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) => hotReloading, liveReloadPort: liveReload.port, local: true, + postRequestPayloadSize, components: opts.components, path: path.resolve(componentsDir), port, diff --git a/src/registry/middleware/index.ts b/src/registry/middleware/index.ts index 871140283..e7bd13206 100644 --- a/src/registry/middleware/index.ts +++ b/src/registry/middleware/index.ts @@ -29,8 +29,10 @@ export const bind = (app: Express, options: Config): Express => { app.use(requestHandler()); if (options.postRequestPayloadSize) { - bodyParserJsonArgument.limit = options.postRequestPayloadSize; - bodyParserUrlEncodedArgument.limit = options.postRequestPayloadSize; + // Type is incorrect since limit can be a string like '50mb' + bodyParserJsonArgument.limit = options.postRequestPayloadSize as number; + bodyParserUrlEncodedArgument.limit = + options.postRequestPayloadSize as number; } app.use(express.json(bodyParserJsonArgument)); diff --git a/src/types.ts b/src/types.ts index 21ccba9dd..11fb75b0b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -163,7 +163,7 @@ export interface Config { plugins: Record void>; pollingInterval: number; port: number | string; - postRequestPayloadSize?: number; + postRequestPayloadSize?: string | number; prefix: string; publishAuth?: PublishAuthConfig; publishValidation: (data: unknown) =>