@@ -6,14 +6,14 @@ by several Node.js web frameworks such as [Express](https://expressjs.com/).
6
6
#### Type signature
7
7
8
8
``` typescript
9
- function middleware(config : Config ): Middleware
9
+ function middleware(config : MiddlewareConfig ): Middleware
10
10
```
11
11
12
- The types of ` Config ` and ` Middleware ` are like below .
12
+ The types of ` MiddlewareConfig ` and ` Middleware ` are like below , except that the config allows
13
+ fields from [ClientConfig ](./ client .md ) too .
13
14
14
15
` ` ` typescript
15
- type Config = {
16
- channelAccessToken?: string,
16
+ type MiddlewareConfig = {
17
17
channelSecret: string,
18
18
}
19
19
@@ -44,8 +44,12 @@ app.post('/webhook', middleware(config), (req, res) => {
44
44
45
45
The middleware returned by ` middleware() ` parses body and checks signature
46
46
validation , so you do not need to use [` validateSignature() ` ](./ validate - signature .md )
47
- directly . Also , you do not need to use [body - parser ](https :// github.com/expressjs/body-parser)
48
- to parse webhook events . If you have a reason to use body - parser for other
47
+ directly .
48
+
49
+ You do not need to use [body - parser ](https :// github.com/expressjs/body-parser)
50
+ to parse webhook events , as ` middleware() ` embeds body - parser and parses them to
51
+ objects . Please keep in mind that it will not process requests without
52
+ ` X-Line-Signature ` header . If you have a reason to use body - parser for other
49
53
routes , * please do not use it before the LINE middleware * . body - parser parses
50
54
the request body up and the LINE middleware cannot parse it afterwards .
51
55
@@ -59,5 +63,9 @@ app.use(middleware(config))
59
63
app.use(bodyParser.json())
60
64
` ` `
61
65
66
+ There are environments where ` req.body ` is pre - parsed , such as [Firebase Cloud Functions ](https : // firebase.google.com/docs/functions/http-events).
67
+ If it parses the body into string or buffer , do not worry as the middleware will
68
+ work just fine. If the pre -parsed body is an object , please use [` validateSignature() ` ](../api -reference /validate -signature.md)
69
+ manually with the raw body .
62
70
63
71
About building webhook server , please refer to [Webhook ](../ guide / webhook .md ).
0 commit comments