OPTIONS http methods gives an empty response on He

2019-02-26 22:19发布

问题:

When I do things locally my CORS calls are working fine

$ curl -i -X OPTIONS "http://localhost:3000/api/v1/login"
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: http://localhost:9000
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers: Content-Type
Content-Type: text/plain
Content-Length: 2
Set-Cookie: connect.sid=blablabla; Path=/; HttpOnly
Date: Wed, 02 Apr 2014 13:46:30 GMT
Connection: keep-alive

OK

But when I deploy and try the same on heroku it does not work anymore:

$ curl -i -X OPTIONS "http://<myapp>.herokuapp.com/api/v1/login"
curl: (52) Empty reply from server

Any idea what that could be due to?

回答1:

I filed a ticket for this, as it turned out, things were not easy to troubleshoot, but the answer is very simple: make your calls using https instead of http



回答2:

Getting no response might be caused by configuration similar to this:

if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
    return 444;
}

Which means that nginx will close the connection without a proper response, that's why this is so difficult to debug.

Search your configuration for the 444 return code. If you find something like the above, just add OPTIONS to the list).



标签: heroku cors