Skip to content

Commit

Permalink
Merge pull request #397 from CPatchane/fix_icon_props
Browse files Browse the repository at this point in the history
Icon props usage with SSL and HOST
  • Loading branch information
gregorylegarec authored Dec 12, 2018
2 parents 97313cf + b10d9cd commit b301358
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
27 changes: 22 additions & 5 deletions src/lib/stack.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global __TARGET__ */
/* eslint-env browser */

import realtime from 'cozy-realtime'
Expand Down Expand Up @@ -26,7 +25,9 @@ function fetchOptions() {
}

let COZY_URL
let COZY_HOST
let COZY_TOKEN
let USE_SSL

const errorStatuses = {
'401': UnauthorizedStackException,
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions test/components/__snapshots__/AppItem.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ ShallowWrapper {
}
}
className="coz-nav-apps-item-icon"
secure={false}
/>
<p
className="coz-label"
Expand All @@ -64,7 +63,6 @@ ShallowWrapper {
}
}
className="coz-nav-apps-item-icon"
secure={false}
/>,
<p
className="coz-label"
Expand All @@ -91,7 +89,7 @@ ShallowWrapper {
},
"className": "coz-nav-apps-item-icon",
"domain": undefined,
"secure": false,
"secure": undefined,
},
"ref": null,
"rendered": null,
Expand Down Expand Up @@ -134,7 +132,6 @@ ShallowWrapper {
}
}
className="coz-nav-apps-item-icon"
secure={false}
/>
<p
className="coz-label"
Expand All @@ -159,7 +156,6 @@ ShallowWrapper {
}
}
className="coz-nav-apps-item-icon"
secure={false}
/>,
<p
className="coz-label"
Expand All @@ -186,7 +182,7 @@ ShallowWrapper {
},
"className": "coz-nav-apps-item-icon",
"domain": undefined,
"secure": false,
"secure": undefined,
},
"ref": null,
"rendered": null,
Expand Down

0 comments on commit b301358

Please sign in to comment.