Need some kind advices on webhooks

Good morning!

I’m novice to everything except markup/some php. Accidently I was involved into making project using Strapi as backend and React as frontend. At the moment i managed to do mostly everything, even deployed it, but right now I’m struggling with telling my frontend to rebuild after entries being added/edited in Strapi. I googled but only found some solutions for those who are using services like Heroku, Netlify etc, while I’m using simple server on Ubuntu.

I’ve tried to solve this using pm2, tried to watch for changes in strapi folders and then rebuild my frontend, but still didn’t succeed.

How can I use webhooks in this case?

System Information
  • Strapi Version: 3.1.0-alpha.5
  • Operating System: 20.04
  • Node Version: 10.23.0
  • NPM Version: 6.14.8

Hey @doc3030 :wave:,

Great to hear you got it working and deployed.
I assume the frontend and Strapi are on the same server. So using a webhook (going over the web) isn’t needed in this case. I think the best solution is to use the afterCreate & afterUpdate lifecycle hooks to trigger an local script that will rebuild/redeploy your frontend. Googling something like ‘node js execute shell command’ should give you an idea on how trigger a rebuild.

I hope you find a solution, good luck!

Ooh and one important thing, you should not use any alpha or beta version any more as they have some security vulnerabilities and aren’t supported anymore. :warning:
Take a look at the migration guides: Or create a new fresh project with the latest (3.4.5) version, this is probably easier then migrating all the way.

P.S. Don’t forget the afterDelete hook :wink:

Yes, i run them both from same server. Thank you so much for your fast response! Will try this soon.

Good luck!

Also checkout this new article (by @ramigs) on the different kind of hooks and there usage:

To be honest, at this moment i didn’t succeed. My frontend is maintained by pm2, so I’m trying to ask Strapi to trigger this command “pm2 restart frontend”, still nothing happens. My code looks like this:

module.exports = {
	lifecycles: {
	    async afterUpdate(result, params, data) {
	    	const { exec } = require("child_process");
	    	exec("pm2 restart frontend", (error, stdout, stderr) => {


Should it be something like this, or I’m getting it wrong?

code from my previous post appeared to be working one, thank you once again for pointing me in the right direction

1 Like