diff --git a/libs/api-gateway/restful/helpers/raw-body-buffer.helper.ts b/libs/api-gateway/restful/helpers/raw-body-buffer.helper.ts new file mode 100644 index 0000000..efbe8a1 --- /dev/null +++ b/libs/api-gateway/restful/helpers/raw-body-buffer.helper.ts @@ -0,0 +1,11 @@ +import { STRIPE_SIGNATURE } from '../constants/special-headers.constant'; + +export const rawBodyBufferHelper = (req: any, res: any, buffer: Buffer, encoding: BufferEncoding): void => { + if (!req.headers[STRIPE_SIGNATURE]) { + return; + } + + if (buffer && buffer.length) { + req.rawBody = buffer.toString(encoding || 'utf8'); + } +}; diff --git a/package.json b/package.json index bfaafc6..6d9836f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hodfords/nestjs-api-gateway", - "version": "10.0.10", + "version": "10.0.11", "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, diff --git a/src/main.ts b/src/main.ts index 4e670d3..360d60b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,8 @@ import { AppModule } from '~app.module'; import { NestExpressApplication } from '@nestjs/platform-express'; import { join } from 'path'; import { env } from '~config/env.config'; +import { json, urlencoded } from 'express'; +import { rawBodyBufferHelper } from 'libs/api-gateway/restful/helpers/raw-body-buffer.helper'; /** * Initialize and configures a NestJS application, @@ -16,6 +18,9 @@ async function bootstrap(): Promise { app.set('trust proxy', ['loopback', 'linklocal', 'uniquelocal']); + app.use(json({ verify: rawBodyBufferHelper, limit: '10mb' })); + app.use(urlencoded({ verify: rawBodyBufferHelper, limit: '10mb', extended: true })); + await app.listen(env.APP_PORT); }