Мы внедрили прокси для Angular 8 приложения, работающего на :4200
, для внутреннего API, работающего на Tomcat 8080
. не работает
с использованием angular версии, как показано ниже Angular CLI: 8.3.20 Узел: 12.13.1 ОС: win32 x64 Angular: 8.2.14
let me mention changes we did.
proxy.conf.json
{
"/student/allstudent": {
"target": "http://localhost:8080",
"secure": false,
"pathRewrite": {
"^/student/allstudent": ""
},
"logLevel": "debug",
"changeOrigin": true
}
}
in `package.json` we added this line "start": "ng serve --proxy-config proxy.conf.json"
In `angular.json` file we have added below proxy config under serve.
"options": {
"browserTarget": "PricingWorkBench-ui:build",
"proxyConfig": "proxy.conf.json"
},
service method look like this in Angular
public getStudentDetails(): Observable<any> {
return this.http.get("http://localhost:8083/student/allstudent").
pipe(
map((data: any) => {
return data;
})
)
}
Все еще мы получаем ошибку ниже, пожалуйста, помогите мне.
Access to XMLHttpRequest at 'http://localhost:8083/student/allstudent' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
core.js:6014 ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://localhost:8083/student/allstudent", ok: false, …}