DymytriiDev/gatsby-webhooks

Have you implemented this in production?

Closed this issue · 1 comments

Generally interested in solving a similar problem :)

I was wondering what your use case is and how you're implementing it?

Hi @laneparton , thanks for reaching out. Short answer is YES.

The use case was a gatsby-based website connected to a headless CMS, so we needed to rebuild the website upon content updates via backend dashboard. The CMS can launch webhooks on such updates occuring. But there was no adequate mechanism at the time, to receive such triggers for rebuild Gatsby to actually update content.

  1. The webhooks.js was added to the project folder, and its deps into package.json
  2. Then, upon commit to master, pipeline script stopped previous running webhooks.js on the end server, transferred the latest repo code to the remote folder, ran "npm install && gatsby build" then again started "forever webhooks.js". Upon this command, the server was able to receive the webhooks to autorebuild the gatsby site programmatically on command, when the content was updated.
  3. Sometimes, you may make multiple minor changes in CMS within like a minute, but obviously, you don't want your server to rebuild multiple times per minute for this. So, the delay parameter on webhooks:36 was added. It means that upon receiving a webhook, the rebuild is scheduled in "x=15000" miliseconds. This allows to alter a few words on a few pages quickly, but rebuild only once. Good idea was to refresh the rebuild delay upon receiving each new request, but was optional in my case.