From 6faabe34e8a56e247953be631a6af31a132b8b0b Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Tue, 19 Jan 2016 19:41:39 +0100 Subject: Optionally specify ws:// and wss:// port in config --- doc/install/Configuration-Settings.md | 7 +++++++ model/config.go | 10 ++++++++++ utils/config.go | 3 +++ web/react/stores/socket_store.jsx | 2 +- web/react/utils/utils.jsx | 11 +++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/doc/install/Configuration-Settings.md b/doc/install/Configuration-Settings.md index 31d4551f6..3dcbe73a6 100644 --- a/doc/install/Configuration-Settings.md +++ b/doc/install/Configuration-Settings.md @@ -41,6 +41,13 @@ Set the number of days before SSO sessions expire. ```"SessionCacheInMinutes" : 10``` Set the number of minutes to cache a session in memory. +```"SecureWebsocketPort": 443``` +The port to use for secure websocket connections being initiated from the client. By default wss:// uses port 443. Some server configurations (e.g. Cloudfoundry) support wss on a different port. + +```"WebsocketPort": 80``` +The port to use for websocket connections being initiated from the client. By default ws:// uses port 80. + + #### Webhooks ```"EnableIncomingWebhooks": true``` diff --git a/model/config.go b/model/config.go index ed56ed0c7..640eb49e5 100644 --- a/model/config.go +++ b/model/config.go @@ -40,6 +40,8 @@ type ServiceSettings struct { SessionLengthMobileInDays *int SessionLengthSSOInDays *int SessionCacheInMinutes *int + WebsocketSecurePort *int + WebsocketPort *int } type SSOSettings struct { @@ -330,6 +332,14 @@ func (o *Config) SetDefaults() { o.ServiceSettings.SessionCacheInMinutes = new(int) *o.ServiceSettings.SessionCacheInMinutes = 10 } + if o.ServiceSettings.WebsocketPort == nil { + o.ServiceSettings.WebsocketPort = new(int) + *o.ServiceSettings.WebsocketPort = 80 + } + if o.ServiceSettings.WebsocketSecurePort == nil { + o.ServiceSettings.WebsocketSecurePort = new(int) + *o.ServiceSettings.WebsocketSecurePort = 443 + } } func (o *Config) IsValid() *AppError { diff --git a/utils/config.go b/utils/config.go index 12d03b5de..c2ae1f7a0 100644 --- a/utils/config.go +++ b/utils/config.go @@ -223,5 +223,8 @@ func getClientConfig(c *model.Config) map[string]string { props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable) + props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort) + props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort) + return props } diff --git a/web/react/stores/socket_store.jsx b/web/react/stores/socket_store.jsx index 24fa79ca6..f1fade305 100644 --- a/web/react/stores/socket_store.jsx +++ b/web/react/stores/socket_store.jsx @@ -49,7 +49,7 @@ class SocketStoreClass extends EventEmitter { protocol = 'wss://'; } - var connUrl = protocol + location.host + '/api/v1/websocket?' + Utils.getSessionIndex(); + var connUrl = protocol + location.host + ((/:\d+/).test(location.host) ? '' : Utils.getWebsocketPort(protocol)) + '/api/v1/websocket?' + Utils.getSessionIndex(); if (this.failCount === 0) { console.log('websocket connecting to ' + connUrl); //eslint-disable-line no-console diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 24042321f..92ad82739 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -1101,6 +1101,17 @@ export function getFileName(path) { return split[split.length - 1]; } +// Gets the websocket port to use. Configurable on the server. +export function getWebsocketPort(protocol) { + if ((/^wss:/).test(protocol)) { // wss:// + return ':' + global.window.mm_config.WebsocketSecurePort; + } + if ((/^ws:/).test(protocol)) { + return ':' + global.window.mm_config.WebsocketPort; + } + return ''; +} + export function getSessionIndex() { if (global.window.mm_session_token_index >= 0) { return 'session_token_index=' + global.window.mm_session_token_index; -- cgit v1.2.3-1-g7c22 From b870c0117f605364fce627cfa3341f84bebbba17 Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Wed, 20 Jan 2016 01:03:17 +0100 Subject: Fix indentation --- web/react/utils/utils.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx index 92ad82739..718095757 100644 --- a/web/react/utils/utils.jsx +++ b/web/react/utils/utils.jsx @@ -1103,13 +1103,13 @@ export function getFileName(path) { // Gets the websocket port to use. Configurable on the server. export function getWebsocketPort(protocol) { - if ((/^wss:/).test(protocol)) { // wss:// - return ':' + global.window.mm_config.WebsocketSecurePort; - } - if ((/^ws:/).test(protocol)) { - return ':' + global.window.mm_config.WebsocketPort; - } - return ''; + if ((/^wss:/).test(protocol)) { // wss:// + return ':' + global.window.mm_config.WebsocketSecurePort; + } + if ((/^ws:/).test(protocol)) { + return ':' + global.window.mm_config.WebsocketPort; + } + return ''; } export function getSessionIndex() { -- cgit v1.2.3-1-g7c22 From ff8df5bf7d45ddd39df8b265ed6af07bd3932d55 Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Wed, 20 Jan 2016 01:26:16 +0100 Subject: Update documentation for WebsocketSecurePort --- doc/install/Configuration-Settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/install/Configuration-Settings.md b/doc/install/Configuration-Settings.md index 3dcbe73a6..7ee440b7c 100644 --- a/doc/install/Configuration-Settings.md +++ b/doc/install/Configuration-Settings.md @@ -41,7 +41,7 @@ Set the number of days before SSO sessions expire. ```"SessionCacheInMinutes" : 10``` Set the number of minutes to cache a session in memory. -```"SecureWebsocketPort": 443``` +```"WebsocketSecurePort": 443``` The port to use for secure websocket connections being initiated from the client. By default wss:// uses port 443. Some server configurations (e.g. Cloudfoundry) support wss on a different port. ```"WebsocketPort": 80``` -- cgit v1.2.3-1-g7c22