title: Access Control Allow Origin header not present with fetch api call
body: <p>So I'm trying to use isomorphic-fetch <a href="https://www.npmjs.com/package/isomorphic-fetch" rel="nofollow">https://www.npmjs.com/package/isomorphic-fetch</a></p>
  
  <p>I have a server written in go that is giving back JSON data. This is how I'm making the call -</p>
  
  <pre><code>export function fetchDistricts(geoState) {
  
      return function (dispatch) {
          dispatch(requestDistricts(geoState));
  
  
          return fetch(`http://localhost:8100/districts/`)
              .then(response =&gt; {console.log(response);})
              .then(json =&gt; {
                  console.log("json");
              });
  }
  </code></pre>
  
  <p>I get this error in the chrome console </p>
  
  <pre><code>Fetch API cannot load http://localhost:8100/districts/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8200' is therefore not allowed access.
  </code></pre>
  
  <p>This is weird, because in my handler I am doing this</p>
  
  <pre><code>func getDistricts(w http.ResponseWriter, r *http.Request) {
      w.Header().Set("Content-Type", "application/jsonp;charset=UTF-8")
      w.WriteHeader(http.StatusOK)
      w.Header().Set("Access-Control-Allow-Origin", "*")
      rows, err := db.Query("SELECT * from districts")
      //other code here
  </code></pre>
  
  <p>Further, this was working </p>
  
  <pre><code>var activitiesDfD =  $.ajax({
      url: "http://localhost:8100/district/1/activities",
      type: "GET",
      dataType: "json"
  });
  
  $.when(activitiesDfD).then(function(data, textStatus, jqXhr) {
  </code></pre>
  
  <p>Why would this fail when using the fetch API and how do I get around this? </p>
  
  <p>Edit-</p>
  
  <p>I've now tried this</p>
  
  <pre><code>func getDistricts(w http.ResponseWriter, r *http.Request) {
      w.Header().Set("Content-Type", "application/jsonp;charset=UTF-8")
      w.Header().Set("Access-Control-Allow-Origin", r.Header.Get(`origin`))
      w.WriteHeader(http.StatusOK)    
  </code></pre>
  
  <p>Incorporating the two suggestions below - but the error is the same. </p>