I am working on Angular app and the backend is Python which is running on port http://127.0.0.1.8000/.
When I try to make a post API call, I'm getting a Cors error. How can I set up a proxy in the Angular app?
I tried with the proxy setting in the Angular app using proxy.conf.json, but the API call is to localhost:4200 and I am getting a HTTP 404 error.
component.ts
aiServiceCall(userInput: string) {
this.aiService
.postReq(userInput)
.subscribe((response) => {
console.log('response', response);
});
}
service.ts
postReq(userInput: string): Observable<any> {
return this.http.post(${environment.API_URL}/chat/, {
params: {
message: userInput
}
})
}
proxyconfirg.json
{
"/api/*": {
"target": "http://127.0.0.1:8000/",
"pathReWrite": {
"^/api/": ""
},
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
environment.ts
export const environment = {
production: false,
API_URL :'http://127.0.0.1:8000'
};