Freddy444 / Songrating-Freddy.Max

MIT License
0 stars 0 forks source link

Issue#43-CORS #79

Closed max-opps closed 10 months ago

max-opps commented 11 months ago

CORS (https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. We have to deal with CORS because different from the previous homework we now have two servers --- the server for our backend and the server for our frontend. At the frontend, our React app will make API requests to the backend (using Axios or fetch). Thus, ensure that at the backend, i.e., in your PHP code, CORS headers are set to allow requests from http://localhost:3000 (or whatever else the local server URL of your frontend is). To keep it simple and for development purposes you can allow the access by any URL, that is, use * --- however, please never do this in production: [see image in #9 of hw 3]

Freddy444 commented 10 months ago

setup HORS headers in my fronted InitController.php file:

header('Access-Control-Allow-Origin: http://localhost:3000'); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Allow-Methods: POST, GET, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type, Custom-Header');