如何使用Firebase托管的Webapp获取不带CORS标头的外部数据? [英] How to get external data without CORS headers with Firebase hosted webapp?

查看:54
本文介绍了如何使用Firebase托管的Webapp获取不带CORS标头的外部数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Ionic2应用托管在Firebase上.我需要从

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

请求的请求上没有'Access-Control-Allow-Origin'标头 资源

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

我可以使用 ionic.config.json 文件中的代理在本地解决此问题:

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

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

但是我不知道将我的应用程序部署到Firebase后如何处理.有可能吗?

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

推荐答案

Firebase文档提供了一个在您的firebase.json中设置Access-Control-Allow-Origin 的示例,以允许对字体文件进行跨域请求.您可以这样调整:

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" : "*"
  } ]
}

这将允许跨域请求所有资源.当然,如果要将其限制为特定资源,则可以调整source值.

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.

这篇关于如何使用Firebase托管的Webapp获取不带CORS标头的外部数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆