Skip to content

Commit 1d9e86b

Browse files
authored
feat: enhance Stripe webhook route with additional content type support (#2631)
1 parent 1093d82 commit 1d9e86b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

apps/api/src/billing/routes/stripe-webhook/stripe-webhook.router.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ const route = createRoute({
1414
summary: "Stripe Webhook Handler",
1515
tags: ["Payment"],
1616
security: SECURITY_NONE,
17+
additionalContentTypes: ["application/json"],
1718
request: {
1819
body: {
1920
content: {
2021
"text/plain": {
2122
schema: z.string()
22-
},
23-
"application/json": {
24-
schema: z.any()
2523
}
2624
}
2725
}

apps/api/src/core/lib/create-route/create-route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ export function createRoute<
4040
security: Required<RouteConfig>["security"];
4141
cache?: CacheConfig;
4242
bodyLimit?: Parameters<typeof bodyLimit>[0];
43+
additionalContentTypes?: string[];
4344
}
4445
>(routeConfig: R) {
45-
const { cache, bodyLimit: bodyLimitOptions, ...openApiConfig } = routeConfig;
46+
const { cache, bodyLimit: bodyLimitOptions, additionalContentTypes, ...openApiConfig } = routeConfig;
4647
let middlewares: MiddlewareHandler[] = [];
4748

4849
if (cache) {
@@ -59,9 +60,15 @@ export function createRoute<
5960
}
6061

6162
if (routeConfig.request?.body?.content) {
63+
const supportedContentTypes = new Set(Object.keys(routeConfig.request.body.content));
64+
if (additionalContentTypes) {
65+
for (const ct of additionalContentTypes) {
66+
supportedContentTypes.add(ct);
67+
}
68+
}
6269
middlewares.push(
6370
contentTypeMiddleware({
64-
supportedContentTypes: new Set(Object.keys(routeConfig.request.body.content))
71+
supportedContentTypes
6572
})
6673
);
6774
}

0 commit comments

Comments
 (0)