cyu / rack-cors

Rack Middleware for handling Cross-Origin Resource Sharing (CORS), which makes cross-origin AJAX possible.
MIT License
3.27k stars 262 forks source link

HTTP 406 Not Acceptable #91

Open dekhaus opened 9 years ago

dekhaus commented 9 years ago

Hi All

I have an AngularJS app backed by a Rails api app (3.2). I'm trying to add a mobile web interface to my AngularJS app and am having trouble communicating with my Rails api backend when using a mobile user-agent (NOTE: when the user-agent is for a 'normal' desktop - everything works great). Some additional details may help ...

The way my app is setup (in development) is that the AngularJS app is served on port 9000 and the Rails api backend is served on port 3000. So I launch my Angular app at http://localhost:9000. The Rails api is accessible at http://localhost:3000/api.

Let's say I have a motd (message of the day) endpoint that my Angular app calls. This works today. I can launch the AngularJS app at http://localhost:9000 and see my app's homepage. When using the default user-agent I can directly access the motd data at http://localhost:3000/api/motd and get a normal response.

However - when I switch my user-agent to be one corresponding to an iOS device - I get a HTTP/1.1 406 Not Acceptable' error. I'm using Rack-Cors and its configured as follows (in config/application.rb) ...

config.middleware.use Rack::Cors do
  allow do
    origins '*'
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end

Any help would be immensely appreciated.

Thanks Dave

cyu commented 6 years ago

@dekhaus Are you using the latest version of the gem? There is an issue with Chrome not liking localhost when a wildcard is used for the origin (https://bugs.chromium.org/p/chromium/issues/detail?id=67743), could that be your issue here?