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

Allow OPTIONS request for CORS-enabled servers #68

Closed
pkosiec opened this issue Mar 28, 2018 · 3 comments
Closed

Allow OPTIONS request for CORS-enabled servers #68

pkosiec opened this issue Mar 28, 2018 · 3 comments

Comments

@pkosiec
Copy link

pkosiec commented Mar 28, 2018

Hello @vektah, firstly I have to say that this library is awesome!

I've run into an issue with CORS enabled server using gqlgen. All OPTIONS requests from client fails (Bad request -{“data”:null,“errors”:[{“message”:“json body could not be decoded: EOF”}]}), because currently only GET and POST requests are supported.

		if r.Method == "GET" {
			...
		} else {

// Assumes that this is POST request

			if err := json.NewDecoder(r.Body).Decode(&reqParams); err != nil {
				sendErrorf(w, http.StatusBadRequest, "json body could not be decoded: "+err.Error())
				return
			}
		}

Can you please add OPTIONS request support?
Thank you very much in advance!

@pkosiec pkosiec changed the title Allow OPTIONS request Allow OPTIONS request for CORS-enabled servers Mar 28, 2018
@vektah
Copy link
Collaborator

vektah commented Mar 28, 2018

Why not use a piece of dedicated middleware for this? I'm quite partial to https://github.com/rs/cors

@pkosiec
Copy link
Author

pkosiec commented Mar 28, 2018

I'm already using it... But I see I probably screwed this up by enabling OptionsPassthrough option in this cors library... I have to confirm this. Anyway thank you for quick response! I will let you know what I found.

@pkosiec
Copy link
Author

pkosiec commented Mar 28, 2018

@vektah Yup, that was my fault. I've accidentally set OptionsPassthrough to true. Thank you with solving my issue and sorry for bothering you!
Also, thanks for polishing the code in your newly created PR! You rock, man!

@pkosiec pkosiec closed this as completed Mar 28, 2018
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