Skip to content

Commit 57140c5

Browse files
committed
feat: allow configuration of JSON and form body parsers
1 parent 4326748 commit 57140c5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/config/schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { BaseConfitSchema } from '@sesamecare-oss/confit';
22
import type { middleware } from 'express-openapi-validator';
33
import type { Level } from 'pino';
4+
import bodyParser from 'body-parser';
45

56
export interface ConfigurationItemEnabled {
67
enabled?: boolean;
@@ -28,8 +29,8 @@ export interface ConfigurationSchema extends BaseConfitSchema {
2829
etag?: boolean;
2930
cookieParser?: boolean;
3031
bodyParsers?: {
31-
json?: boolean;
32-
form?: boolean;
32+
json?: boolean | Parameters<typeof bodyParser.json>[0];
33+
form?: boolean | Parameters<typeof bodyParser.urlencoded>[0];
3334
};
3435
// Set static.enabled to true to enable static assets to be served
3536
static?: ConfigurationItemEnabled & {

src/express-app/app.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export async function startApp<
174174
}
175175

176176
if (routing?.bodyParsers?.json) {
177+
const jsonArgs = typeof routing.bodyParsers.json === 'object' ? routing.bodyParsers.json : {};
177178
app.use(
178179
express.json({
179180
verify(req, res, buf) {
@@ -182,6 +183,7 @@ export async function startApp<
182183
locals.rawBody = buf;
183184
}
184185
},
186+
...jsonArgs,
185187
}),
186188
);
187189
}

0 commit comments

Comments
 (0)