Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andrepibo's avatar

[API error] Response for preflight has invalid HTTP status code 500

Hello everyone,

I am building an API (using Laravel 5) that is gonna be consumed by a front-end and an app. It is being hosted on AmazonEC2. I am doing the authentication using tymondesigns/jwt-auth.

My problem:

  1. When I do an ajax request:
$.ajax({
  url: 'http://myapi.com/call',
  type: 'GET',
  headers: {'Authorization' : 'Bearer token123'},
  crossDomain: true,
  success   : function(data) { console.log(data);},
  error: function(xhr) {console.log(xhr)}
});

I got the error:

XMLHttpRequest cannot load http://myapi.com/call. Response for preflight has invalid HTTP status code 500

However, if I remove the following line, then it works.

  headers: {'Authorization' : 'Bearer token123'},

Through my research I found out the package CORS (barryvdh/laravel-cors). I configured in this way:

'supportsCredentials' => false,
    'allowedOrigins' => ['*'],
    'allowedHeaders' => ['*'],
    'allowedMethods' => ['GET', 'POST', 'PUT',  'DELETE', 'OPTIONS'],
    'exposedHeaders' => [],
    'maxAge' => 0,
    'hosts' => [],

I also tried the solution presented here https://laracasts.com/discuss/channels/requests/laravel-5-cors-headers-with-filters/?page=2 , but it was unsuccessful.

Questions:

  1. Is there any special configuration that I should do on Laravel related to the AmazonEC2 server?

  2. How can I understand and debug this kind of erro? Does Laravel log this kind of erro somewhere?

Thank you very much.

0 likes
0 replies

Please or to participate in this conversation.