CORS (Cross-Origin Resource Sharing) è un meccanismo di sicurezza del browser che controlla se una pagina web da un origin può effettuare richieste a un server su un origin diverso. Per impostazione predefinita, i browser bloccano le richieste cross-origin; il server deve consentirle esplicitamente tramite header di risposta.
La policy same-origin e il problema
Origin = scheme + host + port. These are DIFFERENT origins:
https://app.example.com → https://api.example.com (different host)
http://localhost:3000 → http://localhost:4000 (different port)
Browser blocks the cross-origin request UNLESS the server sends CORS headers allowing it.
