I created an app using Laravel 12 + Sanctum and React.
Locally in my laptop my app is working properly then I upload it to a Windows Server (IIS). With the same port 5173 of React and port 82 for the Laravel app. All of my methods (GET, POST, DELETE AND PATCH) have has been blocked by CORS policy No Access Allow Origin errors.
I tried the following.
Still nothing is working.
My React App in sending Methods.
withCredentials: true,
withXSRFToken: true,
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
config/CORS:
paths' => ['api/*', 'sanctum/csrf-cookie', 'login', 'logout','password-creation','password-reset'],
'allowed_methods' => ['*'],
'allowed_origins' => ['http://localhost:5173'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
My env:
SESSION_DOMAIN=127.0.0.1
SANCTUM_STATEFUL_DOMAINS=127.0.0.1:5173
SESSION_DRIVER=cookie
Screenshot of error:

'allowed_origins' => ['http://localhost:5173'],
Try changing to
'allowed_origins' => ['http://127.0.0.1:5173'].
If you are trying to access the uploaded versions on the server I don't think your allowed origins should be to localhost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With