diff --git a/libs/api-gateway/restful/constants/special-headers.constant.ts b/libs/api-gateway/restful/constants/special-headers.constant.ts new file mode 100644 index 0000000..ca7dd04 --- /dev/null +++ b/libs/api-gateway/restful/constants/special-headers.constant.ts @@ -0,0 +1 @@ +export const STRIPE_SIGNATURE = 'stripe-signature'; diff --git a/libs/api-gateway/restful/services/proxy.service.ts b/libs/api-gateway/restful/services/proxy.service.ts index 912873f..ac604f1 100644 --- a/libs/api-gateway/restful/services/proxy.service.ts +++ b/libs/api-gateway/restful/services/proxy.service.ts @@ -22,6 +22,7 @@ import { WsRequestService } from './ws-request.service'; import { API_GATEWAY_OPTION } from '../../constants/api-gateway.constant'; import { ApiGatewayOption } from '../../types/api-gateway-option.type'; import { ProxyRequest } from '../models/proxy-request.model'; +import { STRIPE_SIGNATURE } from '../constants/special-headers.constant'; @Injectable() export class ProxyService implements OnModuleInit { @@ -87,6 +88,16 @@ export class ProxyService implements OnModuleInit { if (contentType && contentType.startsWith('multipart/form-data;')) { return; } + if (req.headers[STRIPE_SIGNATURE]) { + if (req.body) { + const bodyData = (req as NodeJS.Dict).rawBody; + proxyReq.setHeader('Content-Type', 'application/x-www-form-urlencoded'); + proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData)); + proxyReq.write(bodyData); + } + return; + } + if (req.body) { const bodyData = JSON.stringify(req.body); proxyReq.setHeader('Content-Type', 'application/json'); diff --git a/package.json b/package.json index b0a650c..f5aca1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hodfords/nestjs-api-gateway", - "version": "10.0.8", + "version": "10.0.9", "description": "The API Gateway houses the source code and documentation for the API Gateway - a powerful and versatile solution for managing and deploying APIs within a distributed and microservices-oriented architecture.", "author": "", "private": false,