From b10d9cd8c13002ccf7c2ef05a6c9a95508b7d1a6 Mon Sep 17 00:00:00 2001 From: CPatchane Date: Wed, 12 Dec 2018 10:46:49 +0100 Subject: [PATCH] fix: :bug: Icon props usage with SSL and HOST --- src/lib/stack.js | 27 +++++++++++++++---- .../__snapshots__/AppItem.spec.jsx.snap | 8 ++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/lib/stack.js b/src/lib/stack.js index 39c8e6a64..c356fb2b3 100644 --- a/src/lib/stack.js +++ b/src/lib/stack.js @@ -1,4 +1,3 @@ -/* global __TARGET__ */ /* eslint-env browser */ import realtime from 'cozy-realtime' @@ -26,7 +25,9 @@ function fetchOptions() { } let COZY_URL +let COZY_HOST let COZY_TOKEN +let USE_SSL const errorStatuses = { '401': UnauthorizedStackException, @@ -117,8 +118,9 @@ function getApp(slug) { const cache = {} export const getAppIconProps = () => ({ - domain: COZY_URL, - secure: window.location.protocol === 'https:' + // we mustn't give the protocol here + domain: COZY_HOST, + secure: USE_SSL }) async function initializeRealtime({ @@ -177,16 +179,31 @@ async function initializeRealtime({ } } +const determineURL = (cozyURL, ssl) => { + let url = cozyURL + let host = cozyURL + const protocol = ssl ? 'https' : 'http' + try { + host = new URL(cozyURL).host + if (host) url = `${protocol}://${host}` + } catch (e) { + host = cozyURL + url = cozyURL + } + return { COZY_URL: url, COZY_HOST: host } +} + module.exports = { async init({ cozyURL, token, onCreateApp, onDeleteApp, ssl }) { - COZY_URL = `${__TARGET__ === 'mobile' ? '' : '//'}${cozyURL}` + ;({ COZY_URL, COZY_HOST } = determineURL(cozyURL, ssl)) COZY_TOKEN = token + USE_SSL = ssl await initializeRealtime({ onCreateApp, onDeleteApp, token: COZY_TOKEN, url: COZY_URL, - ssl + ssl: USE_SSL }) }, updateAccessToken(token) { diff --git a/test/components/__snapshots__/AppItem.spec.jsx.snap b/test/components/__snapshots__/AppItem.spec.jsx.snap index afe55e1ff..6639bb608 100644 --- a/test/components/__snapshots__/AppItem.spec.jsx.snap +++ b/test/components/__snapshots__/AppItem.spec.jsx.snap @@ -39,7 +39,6 @@ ShallowWrapper { } } className="coz-nav-apps-item-icon" - secure={false} />

,

,