user6680
user6680

Reputation: 139

Angular PUT request not reaching express code

My app.js backend works perfectly in doing what I need. Postman updates correctly when testing, but the angular http PUT request isn't connecting for some reason. I'm really not sure why since the path is the same. Any help is appreciated.

Error: "Http failure response for http://localhost:3000/api/user/email/5dc1b5bccghdc22788b30922: 0 Unknown Error"

Angular service


   const updateEmail: UserEmailChange = {
     id: id, oldEmail: oldEmail, newEmail: newEmail
   };

   return this.http.put('http://localhost:3000/api/user/email/' + updateEmail.id, updateEmail, { headers: { 'Content-Type': 'application/json' } });

 }

app.js

app.put('/api/user/email/:id', (req, res) =>
User.update(
  {email: req.body.oldEmail},
  {email: req.body.newEmail}
  ).then( user => {
  console.log(user);
  res.json(user);
  // res.sendStatus(200);
  })


.then( user => {
console.log(user);
res.json(user);
// res.sendStatus(200);
}).catch(err => console.log(err)));

Upvotes: 0

Views: 272

Answers (1)

tano
tano

Reputation: 2817

you should substitute the :id to a value in your service.

Upvotes: 1

Related Questions