diff --git a/History.md b/History.md index 3de732487e..bbb1d15280 100644 --- a/History.md +++ b/History.md @@ -6,6 +6,11 @@ packages can be used to perform an OAuth exchange without creating an account and logging in. #1024 +* If you set the `DISABLE_WEBSOCKETS` environment variable, browsers will not + attempt to connect to your app using Websockets. Use this if you know your + server environment does not properly proxy Websockets to reduce connection + startup time. + * Make `Meteor.defer` work in an inactive tab in iOS. #1023 * Allow new `Random` instances to be constructed with specified seed. This diff --git a/packages/livedata/stream_server.js b/packages/livedata/stream_server.js index 6f7b3788b4..cd08344f81 100644 --- a/packages/livedata/stream_server.js +++ b/packages/livedata/stream_server.js @@ -16,8 +16,9 @@ Meteor._DdpStreamServer = function () { // set up sockjs var sockjs = Npm.require('sockjs'); - self.server = sockjs.createServer({ - prefix: '/sockjs', log: function(){}, + var serverOptions = { + prefix: '/sockjs', + log: function() {}, // this is the default, but we code it explicitly because we depend // on it in stream_client:HEARTBEAT_TIMEOUT heartbeat_delay: 25000, @@ -28,7 +29,17 @@ Meteor._DdpStreamServer = function () { // combining CPU-heavy processing with SockJS termination (eg a proxy which // converts to Unix sockets) but for now, raise the delay. disconnect_delay: 60 * 1000, - jsessionid: false}); + jsessionid: false + }; + + // If you know your server environment (eg, proxies) will prevent websockets + // from ever working, set $DISABLE_WEBSOCKETS and SockJS clients (ie, + // browsers) will not waste time attempting to use them. + // (Your server will still have a /websocket endpoint.) + if (process.env.DISABLE_WEBSOCKETS) + serverOptions.websocket = false; + + self.server = sockjs.createServer(serverOptions); self.server.installHandlers(__meteor_bootstrap__.httpServer); // Support the /websocket endpoint