I am currently redesigning and building my website. It was build with simple PHP, HTML, CSS and JavaScript. It had a database to save questions and delete that after resolving. But my current stack is React, PHP (for api) and MySQL. I am using this to avoid NodeJS server because it doesn’t have free support. Currently, my file structure is looking like this:
Website/public/api/ → # Simple PHP crude stuff
Website/src/ → # React codes
So basically the react code fetches the php page to get info from database. The php page just echos the data after getting it from database. Its a simple model. It will work even after compling and building. I saw many people are having issues with cors. What should I do to avoid issues?
Using a React frontend with a PHP backed is no problem here, as long as both the frontend and the backend are on the same hostname. Which seems to be the case here, so all is good.
Just one thing to keep in mind: the raw React source code cannot run in browsers, and needs a build step (typically run through npm build) to generate files that browsers understand. We don’t provide the tools to run those commands on our server, so you’ll need to run them elsewhere, like on your own computer or a CI/CD system. You can then upload the generated files to us (there is no need to upload the node_modules folder or the original React source code).