title: Send request using fetch from HTML file served through golang
body: <p>I am using the following code to serve a HTML file.</p>
  <pre class="lang-golang prettyprint-override"><code>func main() {
      http.HandleFunc(&quot;/&quot;, func(rw http.ResponseWriter, r *http.Request) {
          path := r.URL.Path
          if path == &quot;/&quot; {
              path = &quot;index.html&quot;
          }
  
          http.ServeFile(rw, r, &quot;./&quot;+path)
      })
  
      http.ListenAndServe(&quot;:5555&quot;, nil)
  }
  </code></pre>
  <p>This HTML file includes a JavaScript file that uses fetch to retrieve some data. This works fine when serving through apache, but not when served through the Go-server.</p>
  <p>This is the fetch-request:</p>
  <pre class="lang-js prettyprint-override"><code>const fetchSettings = {
          method: &quot;POST&quot;,
          body: JSON.stringify(requestBody),
          headers: {
              &quot;Content-Type&quot;: &quot;application/json&quot;,
          }
      };
  const response = await fetch(&quot;https://some.url&quot;, fetchSettings);
  </code></pre>
  <p>And here is the error I'm getting:</p>
  <pre><code>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://some.url. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
  
  Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://some.url. (Reason: CORS request did not succeed).
  </code></pre>