From 18c0aad1d9a187d59da6d9f11940ef82b2770ff0 Mon Sep 17 00:00:00 2001 From: Gao Yang Date: Mon, 16 Nov 2020 20:56:27 +0800 Subject: [PATCH] fix: fc egg app body parse (#719) --- packages-serverless/serverless-fc-starter/src/runtime.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages-serverless/serverless-fc-starter/src/runtime.ts b/packages-serverless/serverless-fc-starter/src/runtime.ts index 8feb5ae844ec..dd1e2371ba85 100644 --- a/packages-serverless/serverless-fc-starter/src/runtime.ts +++ b/packages-serverless/serverless-fc-starter/src/runtime.ts @@ -64,8 +64,12 @@ export class FCRuntime extends ServerlessLightRuntime { // const rawBody = 'test'; // req.rawBody = rawBody; - // 应用下自行解决 bodyparser 的问题 - if (!this.isAppMode) { + // 如果需要解析body并且body是个stream + if ( + ['post', 'put', 'delete'].indexOf(req.method.toLowerCase()) !== -1 && + !req.body && + typeof req.on === 'function' + ) { req.body = await getRawBody(req); // TODO: body parser } newReq = req;