Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DELETE method becoming OPTIONS @ Heroku #197

Closed
scanferla opened this issue Mar 25, 2015 · 3 comments
Closed

DELETE method becoming OPTIONS @ Heroku #197

scanferla opened this issue Mar 25, 2015 · 3 comments

Comments

@scanferla
Copy link

Hi,

First of all, thanks for this gem. It is working perfectly except that when I try to delete from AngularJS (I'm using ng-token-auth, Restangular and rails-api) my request is sent as DELETE but Heroku console shows it as OPTIONS.
Chrome says net::ERR_EMPTY_RESPONSE.

AngularJS and Rails are using different domains and the only thing that doesn't work is delete.

It works 100% (including delete) in development mode (localhost:3000 and 0.0.0.0:5000).

I've seen many resources talking about "preflight", etc, etc but nothing has worked for me so far. I don't know how to handle this options method and haven't found any answers on the web.

Thanks in advance!

@scanferla
Copy link
Author

I guess I haven't tried this one: I've moved all rack-cors config from config/application.rb to config.ru.

require 'rack/cors'
use Rack::Cors do
    allow do
        origins '*'
        resource '*',
        :headers => :any,
        :expose  => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
        :methods => [:get, :post, :options, :delete, :put]
    end
end

Source: https://stackoverflow.com/questions/18538549/cant-get-rack-cors-working-in-rails-application/20464939#20464939

It fixed my problem on Heroku.

Thanks anyway for this great gem and I apologize for any inconvenience. I hope this issue can help someone in the future.

@scanferla
Copy link
Author

@lynndylanhurley strangely it only fixed it for a few days, now it's not working again (as described in my first post). And I haven't changed anything in my code.

edit: WEBrick seems to receive DELETE instead of OPTIONS most of the time (but not all). Unicorn stopped working completely.
edit 2: Doing a POST request (creating something) right before trying to delete seems to improve the odds of a successful DELETE instead of OPTIONS.

@lynndylanhurley
Copy link
Owner

Hi @scanferla - this is normal behavior for cross-domain requests. It's called a pre-flight request. Thanks for posting the solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants