Customizing Hot Module Replacement with a webhook

116 Views Asked by At

I was curious if there is a way to modify HMR (in React/NextJs) to listen for webhooks. I'm doing some work in Contentful, and I have to reload the app every time I update Contentful. Contentful has webhooks that can listen for changes, I think it would be awesome to have my dev server listen for these webhooks and auto-update with the edits from Contentful.
Any ideas or suggestions are welcome, Thanks!

1

There are 1 best solutions below

2
stefan judis On

The tricky part here is that webhooks can only be sent to a public URL. You can still use a tool such as ngrok (there are also others but ngrok is the most common one) to spin up a public tunnel to your local machine.

The flow would then be:

  • Contentful sends a webhook to the public ngrok URL
  • the tunneled endpoint is forwarded to your local environment triggering a reload