angularhttpmean-stackmean

localhost appending itself before the backend api in angular


i have put my backend to aws. the backend url works finein postman.

but when i put my backend url in angular service, locahost is getting appended to it in front.

how can i resolve this.

backend url: api.angularapp.site

in my service i called like this:


private url = "api.angularapp.site/api/v1";

public signupFunction(data):Observable<any>{

    const params=new HttpParams()
    .set('firstName', data.firstName)
    .set('lastName', data.lastName)
    .set('mobileNumber', data.mobile)
    .set('email', data.email)
    .set('password', data.password)
    .set('gender',data.gender)
    .set('profilePic',data.profilePic);

    return this.http.post(`${this.url}/users/signup`,params);
  }//end of signup function

but when i run the app and try to signup i get console error:

http://localhost:4200/api.angularapp.site/api/v1/users/signup 404 (Not Found)

why is this localhost attaching itself to the backend call url.

before the url was ** private url = "http://localhost:3000/api/v1";** in that case angular was connecting fine to backend. but now i am not getting how it is appending angular locahost url in start

Please help


Solution

  • you need to provide a full qualified url to the service, otherwise angular will try to do a relative url.

    change the url variable to

    private url = "http://api.angularapp.site/api/v1";
    

    and all should work.