title: golang preflight request error
body: <p>I have set up my Go backend using <code>gorilla/mux</code> and <code>rs/cors</code>. When I try to send a request including a custom header (<code>Bearer</code>) it fails. </p>
  
  <p>My server setup looks like this:</p>
  
  <pre><code>     router := mux.NewRouter().StrictSlash(true)
  router.HandleFunc("/users", GetUsers).Methods("GET")
  router.HandleFunc("/", GetUsers).Methods("GET")
  router.HandleFunc("/tweets", GetTweets).Methods("GET")
  router.HandleFunc("/login", Login).Methods("POST")
  router.HandleFunc("/profile/tweets", ProfileTweets).Methods("GET")
  
  c := cors.New(cors.Options{
      AllowedOrigins: []string{"*"},
      AllowedMethods: []string{"GET", "POST", "PATCH"},
      AllowedHeaders: []string{"Bearer", "Content_Type"},})
  
  handler := c.Handler(router)
  log.Fatal(http.ListenAndServe(":8080", handler))
  </code></pre>
  
  <p>I have tried various other solutions (such as adding <code>OPTIONS</code> in the <code>Methods</code> call.
  The endpoint for which I am trying to pass the <code>Bearer</code> token is the <code>/profile/tweets</code> endpoint.</p>
  
  <p>I'm unsure how to continue with <code>gorilla/mux</code> and <code>rs/cors</code> in terms of adding the preflight request.</p>
  
  <p>The actual error that I get:</p>
  
  <blockquote>
    <p>Fetch API cannot load <a href="http://localhost:8080/profile/tweets" rel="nofollow noreferrer">http://localhost:8080/profile/tweets</a>. Response
    to preflight request doesn't pass access control check: No
    'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin '<a href="http://localhost:4200" rel="nofollow noreferrer">http://localhost:4200</a>' is therefore not allowed
    access. If an opaque response serves your needs, set the request's
    mode to 'no-cors' to fetch the resource with CORS disabled.</p>
  </blockquote>
  
  <p>Thanks!</p>