We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
RIght now, I am doing
mux := http.NewServeMux() mux.HandleFunc("/hello", handleHello) // Other endpoints c := cors.New(cors.Options{ AllowedMethods: []string{"GET"}, }) handler := c.Handler(mux) if err := http.ListenAndServe(":8080", handler); err != nil { log.Fatal("HTTP server error: ", err) }
This enables CORS for all the endpoints, but I want to do so for selective few
The text was updated successfully, but these errors were encountered:
You should be able to just wrap your handler function c.Handler(handleHello) instead of wrapping the entire mux.
c.Handler(handleHello)
Sorry, something went wrong.
You can write like this for each method:
func YourMethod(w http.ResponseWriter, r *http.Request) { w.Header().Set("Context-Type", "application/x-www-form-urlencoded") w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Methods", "DELETE") w.Header().Set("Access-Control-Allow-Headers", "Content-Type") json.NewEncoder(w).Encode(something) }
Thanks for your responses @masalennon @binarypie . Closing this issue
No branches or pull requests
RIght now, I am doing
This enables CORS for all the endpoints, but I want to do so for selective few
The text was updated successfully, but these errors were encountered: