i built a website the frontend using react and the backend using laravel 10 then deployed the frontend part on vercel and the laravel api using a shared hosting
the website works fine when i make the requests using my localhost as a server but when i try using the backend server it gives me this error
Access to XMLHttpRequest at ‘https://mybackend.hstn.me/api/homePage’ from origin ‘https://easylearning-seven.vercel.app’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
the website worked fine before the deploying but after i deployed my website it gives me error
2
Answers
Add Middleware
You have cors file config on config/cors.php and change :
'allowed_origins' => ['*'],
to
'allowed_origins' => ['https://easylearning-seven.vercel.app'],
and you can specify more option about header within this file