From 3557def830d9b6d0ae32c9b92cc1e65298e4bd68 Mon Sep 17 00:00:00 2001 From: Mathis Neumann <mathis@simpletechs.net> Date: Thu, 14 Jul 2016 22:57:56 +0200 Subject: [PATCH] temporarily disable websocket reconnects for production (heroku) deployment --- app/adapters/_baseAdapter.js | 3 ++- app/services/changelog-stream.js | 23 +++++++++++++---------- config/environment.js | 7 +++++++ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/adapters/_baseAdapter.js b/app/adapters/_baseAdapter.js index 6b4759a..4ea1e03 100644 --- a/app/adapters/_baseAdapter.js +++ b/app/adapters/_baseAdapter.js @@ -1,9 +1,10 @@ import Ember from 'ember'; import RESTAdapter from 'ember-data/adapters/rest'; import FixtureAdapter from 'ember-data-fixture-adapter'; +import ENV from 'iobserve-ui/config/environment'; export default RESTAdapter.extend({ - host: 'http://localhost:8080', // TODO: replace with live url + host: ENV.APP.API_ROOT, namespace: 'v1', session: Ember.inject.service() }); \ No newline at end of file diff --git a/app/services/changelog-stream.js b/app/services/changelog-stream.js index ec511b9..52849da 100644 --- a/app/services/changelog-stream.js +++ b/app/services/changelog-stream.js @@ -1,4 +1,5 @@ import Ember from 'ember'; +import ENV from 'iobserve-ui/config/environment'; export default Ember.Service.extend({ changelogQueue: Ember.inject.service(), @@ -11,7 +12,7 @@ export default Ember.Service.extend({ this.set('shouldClose', false); this.debug('setting up websocket', systemId); - const socket = new WebSocket(`ws://localhost:8080/v1/changelogstream/${systemId}`); // TODO: from environment! + const socket = new WebSocket(`${ENV.APP.WEBSOCKET_ROOT}/v1/changelogstream/${systemId}`); this.set('socket', socket); socket.onopen = this.get('events.onOpen').bind(this); @@ -19,15 +20,17 @@ export default Ember.Service.extend({ socket.onmessage = this.get('events.onMessage').bind(this); // automatically reconnect - socket.onclose = () => { - if(!this.get('shouldClose')) { - this.debug('connection lost, reconnecting!'); - this.set('reconnectionTimeout', setTimeout(() => { - this.connect(systemId); - this.set('reconnectionTimeout', null); - }, 500)); - } - }; + if(ENV.APP.WEBSOCKET_RECONNECT) { + socket.onclose = () => { + if(!this.get('shouldClose')) { + this.debug('connection lost, reconnecting!'); + this.set('reconnectionTimeout', setTimeout(() => { + this.connect(systemId); + this.set('reconnectionTimeout', null); + }, 500)); + } + }; + } // close socket connection when the user closes the window/tab or nagivates to a different website window.onbeforeunload = this.get('disconnect').bind(this); diff --git a/config/environment.js b/config/environment.js index f4cbd28..6e58115 100644 --- a/config/environment.js +++ b/config/environment.js @@ -17,6 +17,9 @@ module.exports = function(environment) { APP: { // Here you can pass flags/options to your application instance // when it is created + API_ROOT: 'http://iobserve-api.herokuapp.com', + WEBSOCKET_ROOT: 'ws://iobserve-api.herokuapp.com', + WEBSOCKET_RECONNECT: false // not running on heroku/jetty-runner } }; @@ -27,6 +30,10 @@ module.exports = function(environment) { // ENV.APP.LOG_TRANSITIONS = true; // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; // ENV.APP.LOG_VIEW_LOOKUPS = true; + ENV.APP.API_ROOT = 'http://localhost:8080'; + ENV.APP.WEBSOCKET_ROOT = 'ws://localhost:8080'; + ENV.APP.WEBSOCKET_RECONNECT = true; + } if (environment === 'test') { -- GitLab