Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get external data without CORS headers with Firebase hosted webapp?

I have my Ionic2 app hosted on Firebase. What I need is to get external data from an API service where

No 'Access-Control-Allow-Origin' header is present on the requested resource

I can work around it locally by using proxies in ionic.config.json file:

"proxies": [
{
"path":"/api",
"proxyUrl": "https://api.somwhere.com/"
}
]

But I have no idea how to deal with this after deploying my app to Firebase. Is it somehow possible?

like image 485
j809809jkdljfja Avatar asked Mar 21 '17 19:03

j809809jkdljfja


1 Answers

The Firebase docs have an example of setting the Access-Control-Allow-Origin in your firebase.json to allow cross-origin requests for font files. You could adjust that like this:

"headers": [ {
  "source" : "**",
  "headers" : [ {
    "key" : "Access-Control-Allow-Origin",
    "value" : "*"
  } ]
}

That will allow cross-origin requests for all resources. Of course if you want to restrict it to specific resources, you can adjust the source value.

like image 84
sideshowbarker Avatar answered Oct 27 '22 01:10

sideshowbarker