title: How to send data using fetch and POST request with credentials included?
body: <p>I want to send some data in JSON from my React front-end on port 3000 using fetch, to my node.js server on 3005. I configured cors on my server, but every time I try to send request with cookies, Chrome throws error: </p>
  
  <blockquote>
    <p>Access to fetch at '<a href="http://localhost:3005/user-connected" rel="nofollow noreferrer">http://localhost:3005/user-connected</a>' from origin '<a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'.</p>
  </blockquote>
  
  <p>All console.log's from server code are skipped.</p>
  
  <p>When I delete header in my fetch code</p>
  
  <blockquote>
    <p>"Content-Type", "application/json"</p>
  </blockquote>
  
  <p>I get cookies, but without data. With this header included, but without credentials: "include", I can get my data, but I'll never get both at the same time.</p>
  
  <p>Here's my fetch code:</p>
  
  <pre><code>fetch("http://localhost:3005/user-connected", {
              mode: "cors",
              method: "post",
              headers: [
                  ["Content-Type", "application/json"],
              ],
              credentials: "include",
              body: JSON.stringify({data: "123"})
          })
              .then(data =&gt; data.json())
              .then((data) =&gt; {
                 console.log(`Response: ${JSON.stringify(data)}`);
              }).catch(err =&gt; {
                  console.log(`Error: ${err}`)
          });
  </code></pre>
  
  <p>Node.js cors configuration: </p>
  
  <pre><code>app.use(cors({credentials: true}));
  
  app.use((req, res, next) =&gt; {
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,Content-Type', 'Access-Control-Allow-Origin', 'Origin');
    res.setHeader('Access-Control-Allow-Credentials', true);
    next();
  });
  </code></pre>
  
  <p>And my post route: </p>
  
  <pre><code>let cookiesData = (req, res) =&gt; {
    console.log(`Cookie user-connected: ${req.cookies.io}`)
  
  
    console.log(`Received data: ${JSON.stringify(req.body)}`);
    res.send({ status: "OK" });
  }
  
  router.post("/user-connected", cors({origin: 'http://localhost:3000'}), cookiesData);
  </code></pre>
  
  <p>Is it even possible to do what I want? Or maybe I missed some important configuration?</p>