Thursday, 13 April 2017

Heroku 503 (Service Unavailable) after POST on Angularjs2

I'm trying to Add and get the new data that i just added but i always get 503 (Service Unavailable), The Post Method is working like a charm, but i can't get the new data and i have to restart the server as soon as i add a new element.

the Add service on Angular

addLocation(data) {
return new Promise((resolve, reject) => {
    this.http.post('https://test.herokuapp.com/api/exemple',data)
      .map(res => res.json())
      .subscribe(res => {
        resolve(res);
      }, (err) => {
        reject(err);
      });
});}

The Add on component.ts

onAddSubmit(){

    this.LocationService.addLocation(this.location).then((result) => {
          let id = result['_id'];
          this.router.navigate(['/locations']);
        }, (err) => {
          console.log(err);
        });
      }

The html of the button add

<form (submit)="onAddSubmit()">

And there is the backend service ( Nodejs)

router.post('/musee', function (req,res) {
    musee= new musee(req.body);
    musee.save(function (err) {
        if(err)
            return res.json(err);
        res.json(musee);
    })
});



via Taieb

No comments:

Post a Comment