Meteor, Modulus and secure websockets

我与影子孤独终老i 提交于 2019-12-08 00:44:41

问题


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.

Production app is being hosted on Modulus. SSL enabled.

Things I've done/checked so far

  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 - 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');
  }

UPDATE:
For safe measure, change the Modulus ROOT_URL to your custom domain. So https://myappname-12345.onmodulus.net becomes https://example.com.


回答1:


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.

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



来源:https://stackoverflow.com/questions/27804363/meteor-modulus-and-secure-websockets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!