You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Support for overriding default config added in `[email protected]`
55
+
56
+
By default, Gatsby is using following configuration defaults to parse request body and make it available as `req.body` field in appropriate format:
57
+
58
+
```js
59
+
{
60
+
bodyParser: {
61
+
json: {
62
+
type:"application/json",
63
+
limit:"100kb"
64
+
},
65
+
raw: {
66
+
type:"application/octet-stream",
67
+
limit:"100kb"
68
+
},
69
+
text: {
70
+
type:"text/plain",
71
+
limit:"100kb"
72
+
},
73
+
urlencoded: {
74
+
type:"application/x-www-form-urlencoded",
75
+
limit:"100kb",
76
+
extended:true
77
+
}
78
+
}
79
+
}
80
+
```
81
+
82
+
Those settings work in most cases, but sometimes you might need to adjust them to cover your use case. Gatsby allows exporting an object named `config` from your function handler module. This object allows you to control the `body-parser` middleware used by Gatsby Functions. Gatsby currently supports the `limit`, `type`, and `extended` options for the `bodyParser` configuration, which are documented by [body-parser](https://expressjs.com/en/resources/middleware/body-parser.html). The `limit` property will allow configuration of payload size up to **32mb**.
83
+
84
+
### Examples
85
+
86
+
#### Accessing body as a `Buffer`
87
+
88
+
You can modify what `Content-type` particular `body-parser` middleware can act on. Following configuration will force every request to use `raw` parser and result in function handler receiving `req.body` as a `Buffer`. A setup like this is useful if you are looking to verify signature of webhooks (e.g. https://stripe.com/docs/webhooks/signatures).
89
+
90
+
```js:title=src/api/some-function.js
91
+
exportconstconfig= {
92
+
bodyParser: {
93
+
raw: {
94
+
type:`*/*`,
95
+
},
96
+
},
97
+
}
98
+
99
+
exportdefaultfunctionMyAPIFunction(req, res) {
100
+
// req.body will be a Buffer, no matter what's the `Content-type` header on request
101
+
}
102
+
```
103
+
104
+
#### Increasing or decreasing the payload limit
55
105
56
-
This is not yet supported. [Add a comment in the discussion if this is an
57
-
important use case for you](https://github.com/gatsbyjs/gatsby/discussions/30735).
106
+
By default, the limit is `100kb`. If the request body is larger than that it will result in automatic `413 Request Entity Too Large` response without executing function handler at all.
107
+
108
+
If your use case require a higher limit, you can bump it up in `config`.
109
+
110
+
```js:title=src/api/some-function.js
111
+
// limit payload to 10mb
112
+
exportconstconfig= {
113
+
bodyParser: {
114
+
json: {
115
+
limit:`10mb`,
116
+
},
117
+
},
118
+
}
119
+
```
120
+
121
+
#### TypeScript (`config` object type)
122
+
123
+
You can import `GatsbyFunctionConfig` from `gatsby` to type your `config` export:
0 commit comments