Venkat
Venkat

Reputation: 115

Getting 404 not found in localhost:4200

I'm trying to pass datas from "http://localhost:8082/api/kanchiwork/" to "http://localhost:4200/". My proxy.config.json file is :

    {
      "context": [
        "/api/**"
      ],
      "pathRewrite": {
        "^/api": ""
      },
      "ws": false,
      "target": "http://localhost:8082",
      "secure": false,
      "changeOrigin": true,
      "logLevel": "debug"
    }
  ]

and my service file is given below.

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class PeopleService {

  constructor(private http:HttpClient) { }

  fetchPeople(): Observable<Object>{
    return this.http.get('/api/kanchiwork/');
    //return this.http.get('assets/response.json');
  };

}

. When I tried to pass the values am getting message as ""GET localhost:4200/api/kanchiwork 404 (Not Found)" in console.

Upvotes: 2

Views: 10110

Answers (2)

Amit
Amit

Reputation: 1491

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

Either you can run ng serve --proxy-config proxy.conf.json

else you can update your package.json scripts property:

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

and then run npm start

Note: If you change anything in proxy.conf you need to re-run(ng serve/ npm start) your application to see the changes in action.

Upvotes: 6

Mustahsan
Mustahsan

Reputation: 3862

Try this in proxy.conf.json:

{
  "/api": {
    "target": "http://localhost:8082/",
    "secure": false,
    "pathRewrite": {
      "^/api": ""
    }
  },
  "logLevel": "debug"

}

now run the app with this command:

ng serve --proxy-config proxy.conf.json

Upvotes: 2

Related Questions