From bee2328421abfc3552916b6f536c396120256197 Mon Sep 17 00:00:00 2001 From: echosoar <82163514@qq.com> Date: Fri, 13 Nov 2020 18:00:31 +0800 Subject: [PATCH 1/2] fix: fc egg app body parse --- packages-serverless/serverless-fc-starter/src/runtime.ts | 4 ++-- 1 file changed, 2 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..2b345450f4b1 100644 --- a/packages-serverless/serverless-fc-starter/src/runtime.ts +++ b/packages-serverless/serverless-fc-starter/src/runtime.ts @@ -64,8 +64,8 @@ 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 && typeof req.on === 'function') { req.body = await getRawBody(req); // TODO: body parser } newReq = req; From 4b49d4f75830e261b50fd12aa30fd6b5e49a9c57 Mon Sep 17 00:00:00 2001 From: echosoar <82163514@qq.com> Date: Mon, 16 Nov 2020 20:09:24 +0800 Subject: [PATCH 2/2] fix: fc starter --- packages-serverless/serverless-fc-starter/src/runtime.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages-serverless/serverless-fc-starter/src/runtime.ts b/packages-serverless/serverless-fc-starter/src/runtime.ts index 2b345450f4b1..dd1e2371ba85 100644 --- a/packages-serverless/serverless-fc-starter/src/runtime.ts +++ b/packages-serverless/serverless-fc-starter/src/runtime.ts @@ -65,7 +65,11 @@ export class FCRuntime extends ServerlessLightRuntime { // req.rawBody = rawBody; // 如果需要解析body并且body是个stream - if (['post', 'put', 'delete'].indexOf(req.method.toLowerCase()) !== -1 && typeof req.on === 'function') { + 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;