-
-
Notifications
You must be signed in to change notification settings - Fork 474
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
Response Headers Missing #2
Comments
@troygoode Oh and I'm using the latest version of node.js and express. |
Looks like the issue is that express requires us to manually enable OPTIONS requests (I incorrectly assumed app.GET would also receive requests with an OPTIONS method). Fix incoming. The one part I'm still a bit confused about is that the spec says simple methods, including POST, don't require a preflight OPTIONS request - so it isn't clear to me why an OPTIONS request is even being made against your route. |
I did wonder if it was just that in express, I think OPTIONS is being called due to the fact that the calling domain is http://... and the request is to https://... |
That could be. After further testing it looks like the library works fine, you just have to manually apply it to both OPTIONS and POST in your case. The fix is simply to specify cors for the OPTIONS request as well, so your code would look like this: /* snip */
app.options('/api/login', cors(corsOptions), login.login); //add this line
app.post('/api/login', cors(corsOptions), login.login);
/* snip */ I'm working on updated docs that point this out as well as a Heroku-hosted client/server example that will illustrate (and let me more easily verify) that everything is hunky-dory. |
Interactive example that verifies everything is working using your example code: http://node-cors-client.herokuapp.com/issue-2.html Server code: https://github.com/TroyGoode/node-cors-server/blob/master/app.js#L45 |
Fantastic, thanks for the help! 👍 |
As you said:
Well, the MDN states that a preflight is only not required for a POST when the data is one of the following: |
Ahah, interesting. Thanks! |
First off, let me just say thanks for creating a (potentially) very useful bit of middleware!
The issue I'm having is that none of the headers seem to be injected into the response at all; even though I think my configuration is correct.
I have my routes in
routes.js
, along with the cors middleware:Here's the request from the client:
and the response:
And then I get a normal error in the browser console:
XMLHttpRequest cannot load https://label-logic-live.herokuapp.com/api/login. Origin http://label-logic-live.herokuapp.com is not allowed by Access-Control-Allow-Origin. /user/login:1
The text was updated successfully, but these errors were encountered: