Skip to content

Commit

Permalink
Merge pull request #1359 from opencomponents/postRequestPayloadSize-dev
Browse files Browse the repository at this point in the history
add postRequestPayloadSize on dev and fix type
  • Loading branch information
ricardo-devis-agullo authored Mar 13, 2024
2 parents 3cfb100 + d444206 commit 98bffde
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/cli/facade/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (
{
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions src/registry/middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export interface Config<T = any> {
plugins: Record<string, (...args: unknown[]) => void>;
pollingInterval: number;
port: number | string;
postRequestPayloadSize?: number;
postRequestPayloadSize?: string | number;
prefix: string;
publishAuth?: PublishAuthConfig;
publishValidation: (data: unknown) =>
Expand Down

0 comments on commit 98bffde

Please sign in to comment.