25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import type { NestExpressApplication } from '@nestjs/platform-express';
|
|
import { openApiBodyErrorMiddleware } from './open-api/open-api-body-error.middleware';
|
|
import express from 'express';
|
|
|
|
export const DEFAULT_JSON_BODY_LIMIT = '2mb';
|
|
export const IMPORT_JSON_BODY_LIMIT = '25mb';
|
|
|
|
export function configureHttpBodyParsers(app: NestExpressApplication) {
|
|
// Import preview/confirmation temporarily carries the source CSV/TSV in
|
|
// JSON. Give only these endpoints the larger boundary; keeping ordinary
|
|
// JSON at 2 MiB limits the duplicate raw-buffer + parsed-object footprint.
|
|
app.use(
|
|
'/api/client/send/imports',
|
|
express.json({
|
|
limit: IMPORT_JSON_BODY_LIMIT,
|
|
verify(request, _response, buffer) {
|
|
(request as typeof request & { rawBody?: Buffer }).rawBody = buffer;
|
|
},
|
|
}),
|
|
);
|
|
app.useBodyParser('json', { limit: DEFAULT_JSON_BODY_LIMIT });
|
|
app.useBodyParser('urlencoded', { limit: DEFAULT_JSON_BODY_LIMIT, extended: true });
|
|
app.use('/api/openapi/v1/sms', openApiBodyErrorMiddleware);
|
|
}
|