title: Why do I get error net::ERR_CONNECTION_REFUSED with JSON Server POST request?
body: <p>Resolution : See Hassan Imam's comment below.</p>
  <p>I've got a React project running on http://localhost:3000/ and my JSON server on http://localhost:5000/tasks.</p>
  <p>I can DELETE a task from the server (data on db.json gets deleted) without errors however I'm getting CORS errors in chrome &amp; firefox when I attempt to add a task with POST method.</p>
  <p>I run into the CORS issues below :</p>
  <p>Chrome :</p>
  <pre><code>POST http://localhost/5000/tasks net::ERR_CONNECTION_REFUSED
  </code></pre>
  <p>Firefox :</p>
  <pre><code>Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/5000/tasks. (Reason: CORS request did not succeed).
  </code></pre>
  <p>Starting server with :</p>
  <pre><code>npm run server
  </code></pre>
  <p>App.js :</p>
  <pre><code>const addTask = async (task) =&gt; {
      const res = await fetch('http://localhost/5000/tasks', {
        method: 'POST',
        headers: {
          'Content-type': 'application/json',
        },
        body: JSON.stringify(task),
      });
  
      const data = await res.json();
  
      setTasks([...tasks, data]);
      
    };
  </code></pre>
  <p>package.json</p>
  <pre><code>&quot;scripts&quot;: {
      &quot;start&quot;: &quot;react-scripts start&quot;,
      &quot;build&quot;: &quot;react-scripts build&quot;,
      &quot;test&quot;: &quot;react-scripts test&quot;,
      &quot;eject&quot;: &quot;react-scripts eject&quot;,
      &quot;server&quot;: &quot;json-server --watch db.json --port 5000&quot;
    },
  </code></pre>
  <p>I've attempted to add 'Access-Control-Allow-Origin': '*', to the header but still getting the same errors.</p>
  <p>Anyone have thoughts? Am I supposed to add something to the headers in fetch or somehow configure the JSON server via the command line?</p>