-1

I'm having some issues with an Api in PHP, all tests on postman have passed, but when i'm trying to integrate it with my ReactJS api, ONLY on POST route to login, it is sending me a CORS error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1/select_api/v1/login. (Reason: CORS request did not succeed).

Middleware CORS (PHP): https://gist.github.com/marciowelben/af29ee7b28cb52f7bc2a5f5672e9b18d

React agent: https://gist.github.com/marciowelben/eab681f23102ee353d6e4b16b835265b

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Solution

When implementing the server, even using an middleware, I need to set the OPTIONS on allowed methods.

I used the Tuupola Middleware

https://github.com/tuupola/cors-middleware

And set

$app->add(new Tuupola\Middleware\CorsMiddleware([
"origin" => ["*"],
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTION"],
"headers.allow" => [],
"headers.expose" => [],
"credentials" => false,
"cache" => 0,

]));