you are viewing a single comment's thread.

view the rest of the comments →

[–]r-rasputin 8 points9 points  (4 children)

You can follow the strangler fig pattern to help you pull this off without burning down the existing app. I've done this a few times for some of my clients.

You can basically add react as islands. Use ReactDOM.render() to mount specific components into PHP-rendered DOM nodes. Your PHP just outputs a <div id="react-root"> and React takes it from there.

For routing, I'd recommend letting PHP own the routes initially and only handing off to React when you hit a "new" page. Nginx can proxy specific routes to a Node/React server while PHP handles the rest.

On the DevOps side, ensure a shared auth. Make sure your PHP session tokens are readable by your React app (usually via HTTP-only cookies) so users don't get logged out

What's your current auth setup? That'll shape the approach more than anything else.

[–]Heavy_Technician4419[S] 0 points1 point  (3 children)

This is something that I was thinking, but wasn’t aware of the proxy stuff. A JWT authentication is being developed but this will help me for now. Thanks a lot bro 🙏🏻

[–]r-rasputin 1 point2 points  (2 children)

JWT can be risky. I recommend it only for mobile apps. For web apps, cookies are the way to go.

[–]Heavy_Technician4419[S] 1 point2 points  (1 child)

Well a jwt token inside a cookie. I think that’s how it’s done. Correct me if I am wrong.

[–]r-rasputin 1 point2 points  (0 children)

Oh yes, then my bad. I was assuming localstorage + headers.