[Fixed] GET http://localhost:4200/profile/1 404 (Not Found)

Issue

profile.service.ts

  getProfile(userId:number): Observable<UserModel> {
    return this.httpClient.get<UserModel>('/profile/inquireUserInfo/' + userId);
  }

profile.component.ts

  private getProfile() {
    this.profileService.getProfile(this.userId).subscribe(data => {
      this.userModel = data;
    }, error => {
      console.log(error);
    });
  }

proxy.config.json

{
  "/api/*": {
    "target": "http://localhost:8080",
    "secure": false,
    "logLevel": "debug"
  }
}

package.json

  "scripts": {
    "ng": "ng",
    "start": "ng serve --proxy-config proxy.config.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  }

However, when I run this application, I get a 404 error as seen in the image below:

enter image description here

enter image description here

Solution

Looks like you are not sending api/profile/... with your service, as your proxy reversing api routes to backend server.

Leave a Reply

(*) Required, Your email will not be published