Issue
I've been learning how to use React and I already know substantial PHP. I know that I can use PHP with React since React is only the view in MVC but how do I use PHP with react locally. I have a lamp server running on my Linux machine I want to be able to run it as a backend. Like, let's say I want to make a login screen how do I connect it up. I make the front end in React and the backend in PHP. Do I have to use CORS I'd rather not since, in the end, it's going to be running on the same server.
Solution
You don't need CORS, it seems you are looking for proxy.
Just set your proxy to the listening port of your LAMP API server and then simply use fetch with absolute path from your React app.
Let's say your LAPM server is listening on port 23000
"proxy": "http://localhost:23000",
in package.json file of your React app, then
fetch("/my/api")
will call http://localhost:23000/my/api.
Answered By - Daniele Ricci
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.