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

CORS handling seems broken #69

Open
RenFontes opened this issue Jan 8, 2020 · 4 comments
Open

CORS handling seems broken #69

RenFontes opened this issue Jan 8, 2020 · 4 comments

Comments

@RenFontes
Copy link

They return only a NetworkError with no more information, EVEN when the response had a 200 status and a correct response.

It happened to me while trying to run the http example locally -> https://guide.elm-lang.org/effects/http.html (only change made was to be able to get the error and print it using Debug.toString)

And also when trying to run the same example but pointing the url to a locally running express endpoint with cors enabled for all urls.

image

I also tried it with some test api I found on google and that seemed to work correctly. Not sure if Elm is expecting some headers not provided by express by default or is there is something else I should be doing.

@2mol
Copy link

2mol commented Jan 8, 2020

same issue as elm/elm-lang.org#829

@RenFontes
Copy link
Author

By the way, this issue does not happen when using an F# + giraffe + .net core backend.

Not sure if elm was expecting something else not provided by express, but the fact that the request is successful makes me think that it should had been successful for elm too, or that elm should at least give a more descriptive error. (Specially since it prides itself in its descriptive errors)

@2mol
Copy link

2mol commented Jan 9, 2020

Could you check if your .net core app does a preflight request? You should see one in the networks tab that is OPTIONS instead of GET.

I think elm the language is not doing much wrong here. The good error messages with regards to the compiler don't apply here, since this is a problem that occurs during runtime. But I agree that the Http library could maybe pass more fine-grained information that just NetworkError.

@HenkPoley
Copy link

HenkPoley commented Jan 21, 2020

Just a slight hint: Under Safari/WebKit the server also needs to respond to the OPTIONS method with the CORS headers. Not only on the GET/POST/PUT/DELETE. This OPTIONS request is silently sent, and can often only be found with a MITM attack on the connection, like Charles Proxy or Fiddler.

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

3 participants