I have cloned slim skeleton (https://github.com/slimphp/Slim-Skeleton) which already have CORS implemented. But still when API calls OPTIONS before GET, it sends 405 ERROR "Method not allowed. Must be one of: GET"
Here is my route where I face this error. $group->get('/users', ListUsersAction::class);
$app->group('', function (Group $group) {
$group->post('/user/create', CreateUsersAction::class);
$group->get('/users', ListUsersAction::class);
$group->get('/user/{id}', ViewUserAction::class);
})->add(AuthenticationMiddleware::class);
The same route is working from postman. And same route is working if I remove Authorization token from header.
Execution does not even reach to first line of "AuthenticationMiddleware".
However I tested it by adding same option route without "AuthenticationMiddleware".
like this:
$app->options('/users', function(Request $request, Response $response) {return $response;});
$app->group('', function (Group $group) {
$group->post('/user/create', CreateUsersAction::class);
$group->get('/users', ListUsersAction::class);
$group->get('/user/{id}', ViewUserAction::class);
})->add(AuthenticationMiddleware::class);
This is working. So I guess I forgot to add some code or I did any miskate which causing the error, or the skeleton has a bug.
Can anyone help on this? Thanks in advance.