Home > OS >  how to point webhook to front end
how to point webhook to front end

Time:11-23

I have a webhook being fired when an event occurs. It successfully hits my backend server.

My frontend is localhost:3000

My backend is localhost:5000

My backend route looks like so

   app.get('/webhook', (req, res) => {
    console.log("webhoook fired")});
        res.json({message: "webHook response"}) // How can I point this to front end? 
}

My Question is, My webhook is being fired by a 3rd party that sends a get request to my backend. How I am I able to send a response to my front end within this function? does the res just go back to the 3rd party?

CodePudding user response:

does the res just go back to the 3rd party?

Yes, because they made a request to your server and if required, you can respond to them.

How am I able to send a response to my front end within this function?

If you want to update data in the front-end once your server received data from 3rd-party webhooks, in most cases, you need to use WebSockets to accomplish that. In short, WebSockets allow real-time communication between server and client by keeping a continuous connection between each other. You can look at native WebSockets first, and also check out available libraries such as socket.io or ws :)

  • Related