Jorche
Jorche

Reputation: 187

Implement webhooks with ReactJS frontend and NodeJS backend

I have a ReactJS frontend with a NodeJS backend and I'm trying to implement a 3rd party service: on the documentation of said service it's explained how you can give a URL and the service will use that URL to send an HTTP POST with useful info whenever they detect an event. The way that my app is deployed makes it so only the frontend can make requests to my backend api, so I'm not really sure what URL can I give to this 3rd party service.

What I think could be done I could create a new route with react-router and this URL be the one that the 3rd party points to, in this route I'd have a useEffect() hook that sends the POST of the 3rd party service to my backend, the question is: is this the a normal approach? it seems a little odd to me to have a route with react-router with an empty component that's used to only handle the HTTP POST. Or is there something else that I could do in order to avoid having the frontend as a middleman?

Upvotes: 0

Views: 3932

Answers (1)

Otacílio Maia
Otacílio Maia

Reputation: 309

No this is not the best approach to make it.

I recommend you to create a new service, a proxy service, so you can point this 3rd party service to call your proxy service, and since you have control of your proxy service, you can allow it to call your backend.

You can use node.js to build this proxy service as well.

Upvotes: 1

Related Questions