GoogleCloudPlatform / GoogleCloudPlatform/functions-framework-nodejs
Implicit Request interface extension causes error 'property rawBody does not exist on type'
- 主要言語
- TypeScript
- スター
- 1.4k
- フォーク
- 181
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Cloud functions implicitly extend express Request interface with rawBody (see https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/master/src/invoker.ts#L44):
```ts
// We optionally annotate the express Request with a rawBody field.
// Express leaves the Express namespace open to allow merging of new fields.
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Express {
export interface Request {
rawBody?: Buffer;
}
}
}
```
I get error ` Property 'rawBody' does not exist on type 'Request'` when implement handler which uses Request.rawBody attribute like below:
```ts
import {Response, Request} from 'express';
export class HandlerClass{
public async http(request: Request, response: Response): Promise {
const body = request.rawBody;
...
}
}
```
As a workaround I have to create and use my own type instead of native Express Request:
```ts
import * as express from 'express';
export interface Request extends express.Request {
rawBody: Buffer;
}
```
If you have a look at the `firebase-functions` repository then you will see they use explicit extension of Request interface and then use it in code (https://github.com/firebase/firebase-functions/blob/master/src/providers/https.ts#L33)
I think `functions-framework-nodejs` should change implicit interface extension to explicit and provide stand-alone Request with rawBody attribute to avoid this workaround mess in depended applications code.
コントリビューションガイド
調査の方向性
src/invoker.ts から始め、その暗黙的な Express Request の拡張を、firebase-functions の src/providers/https.ts で使用されている明示的な Request の拡張と比較します。フレームワークが依存する TypeScript アプリケーションに rawBody をどのように公開すべきかを判断し、その後、提供された Request 型を使用する handler がローカルな回避策なしで request.rawBody にアクセスできることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- express, node.js, typescript
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100