Vayun
Vayun

Reputation: 91

Patch request is forever stuck on pending

This is my code on the front end

fetch('http://localhost:5001/api/data', {
                method: 'PATCH',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({
                    "formulaString": formula,
                    "index": props.id
                })

And just to test things; my backend code is kept simple as follows

app.patch('/api/data', (req, res) => { console.log(req.body) }

On triggering the event that leads to the request on the front end; My network has two items :

  1. A preflight with status 204
  2. The actual fetch req that is just stuck on the pending status forever

My backend just logs Undefined which I assume is from the preflight. Not sure on how I should be tackling this; Any help would be much appreciated.

Upvotes: 0

Views: 1000

Answers (1)

sms
sms

Reputation: 1440

Your server not sending any response.

app.patch('/api/data', (req, res) => { console.log(req.body); }

Instead

app.patch('/api/data', (req, res) => { 
 console.log(req.body);
 res.send("working fine") 
}

Upvotes: 1

Related Questions