I am running Angular 9 project connected to firebase.
I am having issues with CORS, I have 2 scenarios:
1. Requesting Image Url from my firestore database
ERROR: Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com .... from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
2. Accessing Fixer.io api
Currency Service
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
@Injectable()
export class CurrencyService {
constructor(private http: HttpClient) {}
async loadCurrencies(): Promise<any> {
var response = this.http.get("http://api.fixer.io/api/latest");
response.subscribe((currencies) => {
console.log(currencies);
});
}
}
ERROR: Access to XMLHttpRequest at 'http://api.fixer.io/api/latest' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I have read a number of articles and posts on stack overflow and the following suggestions were made but they have made no difference.
SOLUTIONS
*****1. Configure Proxy*****
proxy.config.json
{
"/api/*": {
"target": "http://localhost:3000",
"secure": false,
"logLevel": "debug"
}
}
Added the following to angular.json
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
options": {
"browserTarget": "fuse:build",
"proxyConfig": "src/proxy.conf.json"
},
*******2. Installed Google Chrome Extension CORS Unblock*******