title: Javascript - Use fetch on localhost with URL parameters
body: <p>I have a NodeJS server running on port 3001 of my computer. I can use <code>fetch</code> to access a localhost endpoint, like this: <code>fetch("/api_endpoint")</code>.</p>
  
  <p>However, I also want to include url parameters in my GET request.</p>
  
  <p>Normally, I could include url parameters by doing this:</p>
  
  <pre><code>const url = new URL("localhost:3001")
  const params = { sources: JSON.stringify(this.state.sources), timeRange: JSON.stringify(this.state.timeRange), minReacts: this.state.minReacts }
  url.search = new URLSearchParams(params)
  let data = await fetch(url)
  </code></pre>
  
  <p>However, this throws an error:</p>
  
  <blockquote>
    <p>Fetch API cannot load localhost:3001?sources=%5B%22Confessions%22%2C%22Summer+Confessions%22%2C%22Timely+Confessions%22%5D&amp;timeRange=%5B%222017-01-12T23%3A35%3A07.666Z%22%2C%222019-01-12T23%3A35%3A07.667Z%22%5D&amp;minReacts=20. URL scheme must be "http" or "https" for CORS request.</p>
  </blockquote>
  
  <p>How can I use create a fetch request that works with localhost that also uses URL parameters?</p>
  
  <p>Edit:</p>
  
  <p>Adding <code>http://</code> to the front doesn't fix the problem.</p>
  
  <blockquote>
    <p>Access to fetch at '<a href="http://localhost:3001/?sources=%5B%22Confessions%22%2C%22Summer+Confessions%22%2C%22Timely+Confessions%22%5D&amp;timeRange=%5B%222017-01-13T00%3A00%3A17.309Z%22%2C%222019-01-13T00%3A00%3A17.310Z%22%5D&amp;minReacts=20" rel="noreferrer">http://localhost:3001/?sources=%5B%22Confessions%22%2C%22Summer+Confessions%22%2C%22Timely+Confessions%22%5D&amp;timeRange=%5B%222017-01-13T00%3A00%3A17.309Z%22%2C%222019-01-13T00%3A00%3A17.310Z%22%5D&amp;minReacts=20</a>' from origin '<a href="http://localhost:3000" rel="noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.</p>
  </blockquote>