title: 404 error with POST request using express server
body: <p>I am running this function that should post data to my express server. The function is called when a button is clicked.</p>
  <pre><code>const fetchData = async () =&gt; {
      const response = await fetch('http://localhost:1337/api/test', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          message: 'hello world'
        }),
      })
  
      // const data = await response.json()
      const data = await response
      console.log(data)
    }
  
  </code></pre>
  <p>Here is my express configuration</p>
  <pre><code>const express = require('express')
  const cors = require('cors')
  
  const app = express()
  app.use(cors())
  app.use(express.json())
  
  app.get('/api/test', (req: any, res: any) =&gt; {
    console.log(req.body)
    res.json({ status: 'ok' })
  })
  
  app.listen(1337, () =&gt; {
    console.log('Server started on 1337')
  })
  </code></pre>
  <p>The problem is that when I click the button I receive a 404 error for the POST request and  my <code>console.log(response)</code> results in the following.</p>
  <pre><code>Response { type: &quot;cors&quot;, url: &quot;http://localhost:1337/api/test&quot;, redirected: false, status: 404, ok: false, statusText: &quot;Not Found&quot;, headers: Headers, body: ReadableStream, bodyUsed: false }
  ​
  body: ReadableStream { locked: false }
  ​
  bodyUsed: false
  ​
  headers: Headers {  }
  ​
  ok: false
  ​
  redirected: false
  ​
  status: 404
  ​
  statusText: &quot;Not Found&quot;
  ​
  type: &quot;cors&quot;
  ​
  url: &quot;http://localhost:1337/api/test&quot;
  ​
  &lt;prototype&gt;: ResponsePrototype { clone: clone(), arrayBuffer: arrayBuffer(), blob: blob(), … }
  </code></pre>