简体   繁体   English

离子应用程序停止连接到Sails API套接字连接

[英]Ionic app stopped connecting to sails API socket connection

I had a working socket connection using sails v0.11.0 and sails.io.js v0.11.5 until approximately one week ago. 直到大约一周前,我才使用Sails v0.11.0和sails.io.js v0.11.5进行了有效的套接字连接。 I've tried reconfiguring my setup to look something like the solution provided here , but still no connection. 我尝试重新配置安装程序,使其看起来像此处提供的解决方案,但仍然没有连接。

ionic index.html scripts loading ionic index.html脚本加载

<head> 
  <script src="lib/ionic/js/ionic.bundle.js"></script>
  <script src="cordova.js"></script>
  <script src="app.js"></script>
  <script src="lib/socket.io-client/socket.io.js"></script>
  <script src="lib/sails.io.js/sails.io.js"></script>
  <script type="text/javascript">io.sails.url = 'http://my_sails_api_ip:1337';</script>
  <script src="lib/angularSails/dist/ngsails.io.js"></script>
</head>

Loading the scripts in this order had been working for me for about 6 months. 按此顺序加载脚本已经为我工作了大约6个月。 I'm not sure why it stopped. 我不确定为什么会停止。

The error I get in chrome console is; 我在chrome控制台中收到的错误是;

Failed to load resource: the server responded with a status of 404 (Not Found) http://my_sails_api_ip:1337/__getcookie

I've tried setting 'useCORSRouteToGetCookie = false' as has been suggested on other posts. 我已经尝试设置“ useCORSRouteToGetCookie = false”,如其他帖子所建议的那样。 This results in repeated unsuccessful attempts to make the socket connection as opposed to the single error above. 与上面的单个错误相反,这导致反复失败的尝试建立套接字连接。

additional info: My sails api is being ran on an Amazon EC2 instance that "my_sails_api_ip:1337" points to 附加信息:我的sails api在“ my_sails_api_ip:1337”指向的Amazon EC2实例上运行

Edit: I just discovered that if I do ionic serve , to build to my local chrome browser, from the command line instead of ionic run android , to build to my android device, my sails socket connects. 编辑:我刚刚发现,如果我执行ionic serve ,以从命令行而不是ionic run android来构建到本地chrome浏览器,以构建到我的android设备,我的sails套接字就会连接。 I had been successfully connecting from my android device previously. 我以前已经成功从我的android设备连接。

This was due to my upgrade to Cordova 5.3.3 and effects Cordova 5.xx See this blog post by Nic Raboy https://blog.nraboy.com/2015/05/whitelist-external-resources-for-use-in-ionic-framework/ 这是由于我升级到Cordova 5.3.3和效果Cordova 5.xx所致。请参阅Nic Raboy的博客文章https://blog.nraboy.com/2015/05/whitelist-external-resources-for-use-in-离子框架/

I had to tweak the meta tag a bit from Nic's to get my websocket to connect as well. 我不得不稍微调整一下Nic的meta标签,以使我的websocket也能连接。 Here is what that looks like; 看起来像这样;

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM