I am hosting an Angular project on Firebase. I have implemented a payment gateway into the project which works fine on localhost, but on the live environment I am getting the following error:
Access to XMLHttpRequest at 'https://test.oppwa.com/v1/xxx' (redirected from 'https://www.mydomain.cum/api/v1/xxx') from origin 'https://www.mydomain.cum' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
I have come across serval SO questions asking the same question to which the response it typically add the correct Access-Control-Allow-Headers such as in this question
I have added every header under the sun I could find - accordingly my latest set up is as follows:
this.url =
'api/' + resourcePath + '?entityId=xxx';
this.headers = new HttpHeaders()
.set(
'Authorization',
'Bearer xxx=='
)
this.httpOptions = {
headers: this.headers as HttpHeaders,
} as Object;
return this.http
.post(this.url, this.paymentData, this.httpOptions)
.toPromise();
And below is my firebase.json
file in total:
{
"hosting": {
"public": "dist/xxx",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"redirects": [
{
"source": "/api/:path*",
"destination": "https://test.oppwa.com/:path",
"type": 301
}
],
"headers": [
{
"source": "**/*.@(html)",
"headers": [
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Access-Control-Allow-Credentials",
"value": "true"
},
{
"key": "Access-Control-Allow-Methods",
"value": "GET,HEAD,OPTIONS,POST,PUT"
},
{
"key": "Access-Control-Allow-Header",
"value": "Origin, X-Requested-With, Content-Type, Accept, Authorization"
}
]
}
]
}
}
Please can anyone guide me as to what I am doing wrong here.