CORS HandlePreflight not generating any headers
mar1n3r0 opened this issue · 1 comments
mar1n3r0 commented
Stumbled upon this one:
cors-preflight
router.HandleFunc("/profile/tweets", ProfileTweets).Methods("GET","OPTIONS")
c := cors.New(cors.Options{
AllowedMethods: []string{"GET","POST", "OPTIONS"},
AllowedOrigins: []string{"*"},
AllowCredentials: true,
AllowedHeaders: []string{"Content-Type","Bearer","Bearer ","content-type","Origin","Accept"},
OptionsPassthrough: true,
})
Tried to replicate the solution with gorouter:
// Public User routes
router.POST("/v1/dispatch/{command}", commandDispatchHandler)
// Handle preflight
router.OPTIONS("/v1/dispatch/{command}", commandDispatchHandler)
Is there an option we can actually assign 2 methods to a single route at the same time ?
mar1n3r0 commented
Fixed, the solution was to add this to the handler and keep both POST and OPTIONS for the same route.
// Stop here if its Preflighted OPTIONS request
if r.Method == "OPTIONS" {
return
}