I am trying to fetch JSON data from a public API: https://www.gov.uk/api/content/government/collections/local-restrictions-areas-with-an-outbreak-of-coronavirus-covid-19
But the application screams at with with CORS issue.
I am not sure if there is anything I can do to fix the problem.
My Error message
Access to XMLHttpRequest at 'https://www.gov.uk/api/content/government/collections/local-restrictions-areas-with-an-outbreak-of-coronavirus-covid-19' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
My Function
getLocalAreaNews(): Observable<any> {
const url = this.ApiUrl + '/government/collections/local-restrictions-areas-with-an-outbreak-of-coronavirus-covid-19';
const headers = new HttpHeaders()
.set('Access-Control-Allow-Origin', '*');
console.log(url);
return this.http.get<any>(url, {
headers: headers
});
}
ngOnInit(): void {
this.GovApi.getLocalAreaNews().subscribe((data) => {
console.log(data);
});
}