使用Firebase + IONIC2 + Angularjs的CORS:仍然不存在“访问控制允许来源” [英] CORS with Firebase+IONIC2+Angularjs: No 'Access-Control-Allow-Origin' still exists

查看:68
本文介绍了使用Firebase + IONIC2 + Angularjs的CORS:仍然不存在“访问控制允许来源”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了所有建议,也遵循了离子性建议,如何克服CORS问题并摆脱错误: Access-Control-Allow-Origin 没有成功。我想我缺少代理中的确切路径转换:

I read all the suggestions and also followed the ionic suggestion how to overcome the CORS issue and get rid of the error: Access-Control-Allow-Origin with no success. I think I am missing the exact path conversion in proxies:

我尝试在Firebase中访问的URL是:
< a href = https://firebasestorage.googleapis.com/v0/b/Test1-xxxxx.appspot.com/o/userData rel = nofollow noreferrer> https://firebasestorage.googleapis.com/v0/b /Test1-xxxxx.appspot.com/o/userData 。

我的本地主机URL是:本地主机:8100。

My local host URL is: localhost:8100.

我不知道如何编辑ionic.config.json中的路径 proxyUrl 设置:

I don't understand how should I edit the path and proxyUrl settings in ionic.config.json:

{
"name": "Test1", 
"app_id": "", 
"v2": true, 
"typescript": true,

"proxies": [{

  "path": "...",

  "proxyUrl": "..."

}]}

我尝试了很多方法都没有成功,可能是我遗漏了重点。我是新来的Apps。我从使用angular2 + Ionic2

I have tried many ways with no success, I am probably missing the point. I am new to Apps in general. I am starting with Web app using angular2+Ionic2

推荐答案

将代理设置为

 "proxies": [
    {
      "path": "/v0",
      "proxyUrl": "https://firebasestorage.googleapis.com/v0"
    }
  ]

然后在您的应用中应该将api称为 /v0/b/Test1-xxxxx.appspot.com/o/userData

Then in your app you should call api as /v0/b/Test1-xxxxx.appspot.com/o/userData

这也是一个问题,因为当您编译时,它将调用相同的请求,同时应调用firebase。因此,我的建议是添加常量 BaseUrl ,在开发环境中,当您进行生产时,该字段应为空,将其设置为 https://firebasestorage.googleapis.co ,因为捆绑时没有代理。

Also this is a problem because when you compile it will call the same request meanwhile it should call firebase. So my recommendation would be to add constant BaseUrl and in dev it should be empty when you do production set it to "https://firebasestorage.googleapis.co" since when you bundle there is no proxy.

这篇关于使用Firebase + IONIC2 + Angularjs的CORS:仍然不存在“访问控制允许来源”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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