title: Has been blocked by CORS policy: Response to preflight request doesn’t pass access control check
body: <p>I have created trip server. It works fine and we are able to make <code>POST</code> request by Insomnia but when we make <code>POST</code> request by axios on our front-end, it sends an error:</p>
  
  <pre><code>has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.
  </code></pre>
  
  <p>Our request on axios:</p>
  
  <pre><code>let config = {
  headers: {
    "Content-Type": "application/json",
    'Access-Control-Allow-Origin': '*',
    }
  }
  
  let data = {
    "id": 4
   }
  
   axios.post('http://196.121.147.69:9777/twirp/route.FRoute/GetLists', data, config)
     .then((res) =&gt; {
        console.log(res)
       })
      .catch((err) =&gt; {
        console.log(err)
     });
  } 
  </code></pre>
  
  <p>My go file:</p>
  
  <pre><code>func setupResponse(w *http.ResponseWriter, req *http.Request) {
      (*w).Header().Set("Access-Control-Allow-Origin", "*")
      (*w).Header().Set("Access-Control-Allow-Methods", "POST,GET,OPTIONS, PUT, DELETE")
  
      (*w).Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
  }
  
  
  func WithUserAgent(base http.Handler) http.Handler {
      return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  
      ctx := r.Context()
      ua := r.Header.Get("Jwt")
      ctx = context.WithValue(ctx, "jwt", ua)
  
      r = r.WithContext(ctx)
  
      setupResponse(&amp;w, r)
       base.ServeHTTP(w, r)
    })
  }
  
  const (
      host     = "localhost"
      port     = 5432
      user     = "postgres"
      password = "postgres"
      dbname   = "postgres"
  )
  
  func main() {
  
      psqlInfo := fmt.Sprintf("host=%s port=%d user=%s "+
             "password=%s dbname=%s sslmode=disable",
                 host, port, user, password, dbname)
  
      server := &amp;s.Server{psqlInfo}
  
      twirpHandler := p.NewFinanceServiceServer(server, nil)
  
      wrap := WithUserAgent(twirpHandler)
        log.Fatalln(http.ListenAndServe(":9707", wrap))
  }
  </code></pre>
  
  <p>As I said before on Insomnia it works great, but when we make an axios <code>POST</code> request, on browser's console following appears: </p>
  
  <blockquote>
    <p>has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.</p>
  </blockquote>