jValls
jValls

Reputation: 39

Laravel 5.2 and angularjs satellizer CORS

I am building an api and I am having a lot of problems with the client side and the CORS.

The laravel app works correctly and I've used the barryvdh/laravel-cors to enable CORS in the server side. If I try the route with postman all works as expected and the app return the JWT. cors configuration:

return [
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['*'],
'exposedHeaders' => [],
'maxAge' => 0,
'hosts' => [],];

The problem starts when I want to login using angularjs and satellizer I am not able to receive the token due to the following CORS problem

XMLHttpRequest cannot load http://localhost:8080/authenticate. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

If I check the headers it looks like there is a problem with the server response:

Server response headers

I am using the laravel server to test it and grunt in the front-end.

I would like to ask if someone could help me here. I am stuck since the last week with this problem.

Upvotes: 1

Views: 228

Answers (1)

Jornve
Jornve

Reputation: 309

I work also with Laravel 5.2 and have no problems with CORS after adding barryvdh/laravel-cors properly. Did you modified your routes.php file?

Route::group(['prefix' => 'api', 'middleware' => 'cors'], function() {Your API routes...}

Upvotes: 1

Related Questions