Ver Fonte

fix(api-gateway): checking for buffer length

Karol Sójko há 1 ano atrás
pai
commit
f65809ef30
1 ficheiros alterados com 3 adições e 1 exclusões
  1. 3 1
      packages/api-gateway/bin/server.ts

+ 3 - 1
packages/api-gateway/bin/server.ts

@@ -78,7 +78,9 @@ void container.load().then((container) => {
         limit: '50mb',
         verify: (_req: IncomingMessage, _res: ServerResponse, buf: Buffer, encoding: string): void => {
           try {
-            JSON.parse(buf.toString(encoding as BufferEncoding))
+            if (buf && buf.length > 0) {
+              JSON.parse(buf.toString(encoding as BufferEncoding | 'utf8'))
+            }
           } catch (error) {
             logger.error(`Invalid JSON: ${(error as Error).message}. Request body: ${buf.toString()}`)
           }