So you will have 2 diffrent projects one which will be your php server and it will only serve JSON data and one will be your react app which will call the php APIs get JSON and display it.
In local you can start your php project at localhost:8081 and your react project at localhost:8080 and when you want to call any api you can call it at localhost:8081/test.
And in prod your php project will be deployed at lets say api.example.com
and react project will be deployed at example.com. So when you want to call any apis in prod you send a request to api.example.com/test.
Axios (axios-http.com/) is a good library for making this kind of requests, you can do somthing like below
// check if we're in dev and set base url correctlyconstbaseURL=process.env.NODE_ENV==='development'?'localhost:8081':'api.example.com';// create a axios instanceconstaxios=Axios.create({baseURL})// send a requestaxios.get('/test').then(res=>console.log(res))
What this will do is set the correct base url and whenever you send a request it will add the base url before the path ('/test') so your requests will go to right address.
With this your server (php) and client (react) are two different things and you can easily swap react for vue or angular or swap php for ruby on rails or python.
If you are not intending to use client server architecture , It may be wise to use vue instead of react. Laravel even sponsoring vue because it is solving a lot of it's problems without much tooling like react.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So you will have 2 diffrent projects one which will be your php server and it will only serve JSON data and one will be your react app which will call the php APIs get JSON and display it.
In local you can start your php project at localhost:8081 and your react project at localhost:8080 and when you want to call any api you can call it at
localhost:8081/test
.And in prod your php project will be deployed at lets say api.example.com
and react project will be deployed at example.com. So when you want to call any apis in prod you send a request to
api.example.com/test
.Axios (axios-http.com/) is a good library for making this kind of requests, you can do somthing like below
What this will do is set the correct base url and whenever you send a request it will add the base url before the path ('/test') so your requests will go to right address.
With this your server (php) and client (react) are two different things and you can easily swap react for vue or angular or swap php for ruby on rails or python.
okay with this method if we realize a web application the loading speed of the site and the seo referencing will be obtained
If you are not intending to use client server architecture , It may be wise to use vue instead of react. Laravel even sponsoring vue because it is solving a lot of it's problems without much tooling like react.