Skip to content

Add Access-Control-Allowed-Methods with mux.Route.Methods() #353

@fharding1

Description

@fharding1

What version of Go are you running? (Paste the output of go version)
go version go1.9.3 linux/amd64

What version of gorilla/mux are you at? (Paste the output of git rev-parse HEAD inside $GOPATH/src/github.com/gorilla/mux)
c0091a0

Describe your problem (and what you have tried so far)
When using mux.Route.Methods() to set allowed methods, there is no easy way to add CORS. I had a middleware for this, but you run into problems when you have two of "the same" URLs, for example /reports/{eventKey}/{matchKey} (PUT) and /reports/{eventKey}/{team} (GET). It would be nice if there was a simple way to integrate CORS with .Methods(), or if there is one already if it were more clear in the documentation.

r.Handle("/reports/{eventKey}/{matchKey}", submitReport).Methods("PUT")
r.Handle("/reports/{eventKey}/{team}", getReportsByEventAndTeam).Methods("GET")

An OPTIONS request or request to either endpoint should have Access-Control-Allow-Methods: "GET", "PUT", "OPTIONS".

Paste a minimal, runnable, reproduction of your issue below (use backticks to format it)
N/A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions