流星,模数和安全的websockets [英] Meteor, Modulus and secure websockets

查看:112
本文介绍了流星,模数和安全的websockets的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在流星 - >模数上下文中绕过websockets和xhr。我有时会注意到很长的响应时间,显然是因为当无法连接时,websockets会回落到xhr ......我正在尝试诊断原因。

Trying to get my head around websockets and xhr in a Meteor -> Modulus context. I've been noticing lengthy response times on occasion apparently due to websockets falling back to xhr when it can't connect...I'm trying to diagnose why.

生产应用程序正在Modulus上托管。已启用SSL。

Production app is being hosted on Modulus. SSL enabled.

到目前为止我已完成/检查过的事情


  1. 升级所有内容:该应用程序一直在1.0.2.1(最新)运行,但最初在~0.65天内创建了
    。作为第一项业务,我将
    标准应用程序包升级到meteor-platform软件包并重新启动
    服务器。没有变化。

  2. 模数:检查...模数不需要任何明确的命令来启用安全的websockets

  3. 流星:检查......截至默认情况下启用 Meteor 0.6.3.1 websockets。

  4. 出版物尺寸:我确信在我的
    出版物中我可能会更加节俭,但这些出版物总共约为1.4kb。

  5. 浏览器安全策略:合理地确定这是可以的(见下文)

  1. Upgrade all the things: The app has been running at 1.0.2.1 (latest) but was originally created during the ~0.65 days. As first order of business I upgraded the standard-app-packages to meteor-platform packages and restarted the server. No change.
  2. Modulus: Check...Modulus does not require any explicit commands to enable secure websockets
  3. Meteor: Check...As of Meteor 0.6.3.1 websockets are enabled by default.
  4. Publication size: I'm sure I could be a bit more thrifty in my publications, but these appear to be about 1.4kb in total.
  5. Browser Security policy: Reasonably sure this is ok (see below)

相对新手在这里所以有关下一步检查的任何想法或建议非常感谢。

Relative newbie here so any thoughts or advice on what to check next are greatly appreciated.

PS - 类似的,未回答的问题这里这里

PS - Similar, unanswered questions here and here

  BrowserPolicy.content.disallowConnect();

  //
  //Allow Meteor DDP Connections
  //
  var rootUrl = __meteor_runtime_config__.ROOT_URL;
  console.log('ROOT_URL: ' + rootUrl);

  //Allow DDP connections for local development
  if (rootUrl == 'http://localhost:3000/') {
    BrowserPolicy.content.allowConnectOrigin(rootUrl);
    BrowserPolicy.content.allowConnectOrigin(rootUrl.replace(/http(s?)/, 'ws$1'));
  }

  //Allow DDP connections for staging server currently using Meteor's free hosting
  if (rootUrl == 'http://staging.example.com') {
    BrowserPolicy.content.allowConnectOrigin('https://*.meteor.com');
    BrowserPolicy.content.allowConnectOrigin('wss://*.meteor.com');
  }

  //Allow DDP connections for Modulus
  if (rootUrl == 'https://myappname-12345.onmodulus.net') {
    BrowserPolicy.content.allowConnectOrigin('https://example.com');
    BrowserPolicy.content.allowConnectOrigin('wss://example.com');
  }

更新:

为安全起见,请将模数ROOT_URL更改为自定义域。所以 https://myappname-12345.onmodulus.net 变为 https://example.com

推荐答案

无论你做什么,你的用户中至少有一小部分人会回到XHR。到处都没有完全支持WebSockets,特别是在移动设备上。使用SSL可以获得更广泛的支持,但仍然无处不在。

No matter what you do it's likely at least a small subset of your users will fall back to XHR. WebSockets are still not fully supported everywhere, especially on mobile. Using SSL gets you much broader support, but still not ubiquitous.

只要WebSockets看起来对您有用,您就无法做其他事情。根据设计,XHR将具有非常长的响应时间。 XHR通过打开与服务器的长(~30s)连接来工作。如果服务器无话可说,它将关闭连接并再次执行。这允许服务器在该30s窗口中的任何时间立即响应。这些XHR民意调查显示响应时间很长,但完全正常。

As long as WebSockets appear to be working for you, there's not much else you can do. XHR, by design, will have very long response times. XHR works by opening long (~30s) connections to the server. If the server has nothing to say it will close the connection and do it again. This allows the server to immediately respond at anytime in that 30s window. These XHR polls show up as long response times but are perfectly normal.

免责声明:我是模数员工

Disclaiming: I'm a Modulus employee

这篇关于流星,模数和安全的websockets的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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