From 469d01fcb61288e384e5201204f2e51ddaaf956a Mon Sep 17 00:00:00 2001 From: Vaibhav Rathore Date: Tue, 6 Oct 2020 15:10:28 +0530 Subject: [PATCH 1/2] wss protocol added --- src/config/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index 6fcb7f8d3..c0c84bd70 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -2,16 +2,18 @@ const envVariables = process.env; const API_PORT = envVariables.REACT_APP_GLIFIC_API_PORT; const PROTOCOL = window.location.protocol; -const HOSTNAME = window.location.hostname; const API_PREFIX = envVariables.REACT_APP_API_PREFIX; +const HOSTNAME = API_PREFIX + ? `${API_PREFIX}.${window.location.hostname}` + : window.location.hostname; -let GLIFIC_BACKEND_URL = API_PREFIX - ? `${PROTOCOL}//${API_PREFIX}.${HOSTNAME}` +const GLIFIC_BACKEND_URL = API_PORT + ? `${PROTOCOL}//${HOSTNAME}:${API_PORT}` : `${PROTOCOL}//${HOSTNAME}`; -GLIFIC_BACKEND_URL = API_PORT ? `${GLIFIC_BACKEND_URL}:${API_PORT}` : GLIFIC_BACKEND_URL; +const SOCKET_URL = PROTOCOL === 'http:' ? `ws://${HOSTNAME}` : `wss://${HOSTNAME}`; -export const SOCKET = API_PORT ? `ws://${HOSTNAME}:${API_PORT}/socket` : `ws://${HOSTNAME}/socket`; +export const SOCKET = API_PORT ? `${SOCKET_URL}:${API_PORT}/socket` : `${SOCKET_URL}/socket`; export const SENTRY_DSN = envVariables.SENTRY_DSN; export const FLOW_EDITOR_API = GLIFIC_BACKEND_URL + '/flow-editor/'; export const GLIFIC_API_URL = GLIFIC_BACKEND_URL + '/api'; From 22b406daa0f34038ab1841cc53ab1c45040d5a08 Mon Sep 17 00:00:00 2001 From: Vaibhav Rathore Date: Tue, 6 Oct 2020 15:22:21 +0530 Subject: [PATCH 2/2] code cleanup --- src/config/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index c0c84bd70..a730e0e1e 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -11,9 +11,11 @@ const GLIFIC_BACKEND_URL = API_PORT ? `${PROTOCOL}//${HOSTNAME}:${API_PORT}` : `${PROTOCOL}//${HOSTNAME}`; -const SOCKET_URL = PROTOCOL === 'http:' ? `ws://${HOSTNAME}` : `wss://${HOSTNAME}`; +const SOCKET_PROTOCOL = PROTOCOL === 'https:' ? `wss://${HOSTNAME}` : `ws://${HOSTNAME}`; -export const SOCKET = API_PORT ? `${SOCKET_URL}:${API_PORT}/socket` : `${SOCKET_URL}/socket`; +export const SOCKET = API_PORT + ? `${SOCKET_PROTOCOL}:${API_PORT}/socket` + : `${SOCKET_PROTOCOL}/socket`; export const SENTRY_DSN = envVariables.SENTRY_DSN; export const FLOW_EDITOR_API = GLIFIC_BACKEND_URL + '/flow-editor/'; export const GLIFIC_API_URL = GLIFIC_BACKEND_URL + '/api';