Webhook payload too big for the default Express app

Webhook payload too big for the default Express app

luistmartins
Shopify Partner
21 2 2

I've running into an issue with an app built using the Shopify CLI boilerplate.

 

I am subscribing to few webhook topics, including `ORDERS_UPDATED`. For most orders the webook runs fine and responds back to Shopify with a 200.

 

However for some orders it is bumping into a problem saying that the payload was too big and rejected by the server. Error appear to be triggered by the package `body-parser`:

 

```

PayloadTooLargeError: request entity too large

dfw [info] at readStream (/app/node_modules/raw-body/index.js:156:17)

```

 

I've tried to adjust settings for that module as listed below but as soon as I do that the server appears go get no payload whatsoever and therefore refuses the webhook due to missing data.

 

```

app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.text({ limit: '50mb' }));
app.use(bodyParser.raw({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
```
 
 
Anyone had this experience? How did you get around it?
Reply 1 (1)

luistmartins
Shopify Partner
21 2 2

Just to answer my own question, solution to include another middleware in the route declaration for the webhooks.

 

So if you've started with the CLI boilerplate, that would be:

 

app.post(
  shopify.config.webhooks.path,
  express.text({ type: '*/*', limit: '3MB' }),
  shopify.processWebhooks({ webhookHandlers: GDPRWebhookHandlers })
);