rubyonjets / jets

Ruby on Jets
http://rubyonjets.com
MIT License
2.6k stars 181 forks source link

Handle OPTIONS pre-flight requests #237

Closed sofianegargouri closed 5 years ago

sofianegargouri commented 5 years ago

Checklist

My Environment

Software Version
Operating System MacOS Mojave 10.14.4
Jets 1.8.9
Ruby 2.5.3

Expected Behaviour

OPTIONS requests are supposed to return a 200 HTTP Status with the access-control-allow-origin header set

Current Behavior

Returns a 404 error

Step-by-step reproduction instructions

Just setup any route and call it from a JS script in a browser (Postman won't trigger the error)

Code Sample

When running an HTTP request to a Jets app from another app (with CORS), OPTIONS requests are not handled and always return a 404 error.

Solution Suggestion

ChrisBr commented 5 years ago

I tried it with jets-2.1.1 in chrome and it works fine for me.

Test

HTML file I used for testing:

<html>
  <script>
    function httpGet(theUrl)
    {
      var xmlHttp = new XMLHttpRequest();
      xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
      xmlHttp.setRequestHeader("X-Amz-Date", "CORS");
      xmlHttp.send( null );

      return xmlHttp.responseText;
    }
    var res = httpGet("http://localhost:8888");
    console.log(res);
  </script>
</html>

Jets configuration:

Jets.application.configure do
  config.cors = true
end

Caveats

@sofianegargouri can you please verify so that we can close the issue. Thanks 🙏

tongueroo commented 5 years ago

Closing until there are more details. Thanks!