I am trying to execute the below function in my Ionic Angular app, cloudFunctionUrl is a cloud function I have in my firebase project:
import { HttpClient } from '@angular/common/http';
private http: HttpClient
like(post) {
this.http.post('cloudFunctionUrl', JSON.stringify(body), {
responseType: 'text'
}).subscribe((data) => {
console.log(data);
}, (error) => {
console.log(error);
});
}
To get over the CORS issue, I installed the Allow CORS: Access-Control-Allow-Origin chrome plugin. Below is a list of the whitelisted domains:
- http://localhost:8100
- chrome.google.com
- localhost
- localhost:8100
- localhost:8100/profile
- cloudFunctionUrl
The like
function above is executed on localhost:8100/profile
.
I'm experiencing two issueS:
- I navigate to localhost:8100/profile no problem, but when I execute
like
, I get this error message:
Access to XMLHttpRequest at 'cloudFunctionUrl' from origin 'http://localhost:8100' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
- If I go to the firebase console, & I have the CORS plugin turned on, it says "There was an error loading your projects"
Can someone please tell me how I can resolve this?
I also tried to add the below headers to the request, but the error is still appearing:
let headers = new HttpHeaders({
'Access-Control-Allow-Origin': '*'
});
this.http.post('cloudFunctionUrl', JSON.stringify(body), {
headers: headers,
responseType: 'text'
}