Skip to content

Commit

Permalink
Merge pull request #409 from CPatchane/fix_real
Browse files Browse the repository at this point in the history
Always use the protocl for COZY_URL by default
  • Loading branch information
CPatchane authored Dec 18, 2018
2 parents 1d24486 + fee30c6 commit 3cc8c31
Showing 1 changed file with 4 additions and 27 deletions.
31 changes: 4 additions & 27 deletions src/lib/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,8 @@ export const getAppIconProps = () => {
}
}

async function initializeRealtime({
onCreateApp,
onDeleteApp,
ssl,
url,
token
}) {
// Let's check the url. By default it's just the domain, but some apps are
// passing a full URL with protocol.
let parsedURL
try {
parsedURL = new URL(url)
} catch (error) {
console.warn(
`Cannot parse URL for realtime, using ${url} as domain (${error.message})`
)
}

const realtimeConfig = { token }
if (parsedURL) {
realtimeConfig.url = url
} else {
// Protocol is http/https here, it is mapped to ws/wss by cozy-realtime
realtimeConfig.url = `${ssl ? 'https:' : 'http:'}${url}`
}
async function initializeRealtime({ onCreateApp, onDeleteApp, url, token }) {
const realtimeConfig = { token, url }

try {
const realtimeApps = await realtime.subscribeAll(
Expand Down Expand Up @@ -195,10 +172,10 @@ const determineURL = (cozyURL, ssl) => {
// only on mobile we get the full URL with the protocol
host = new URL(cozyURL).host
url = !!host && `${protocol}://${host}`
} catch (e) {} //eslint-disable-line no-empty
} catch (e) {} // eslint-disable-line no-empty

host = host || cozyURL
url = url || `//${host}`
url = url || `${protocol}://${host}`

return { COZY_URL: url, COZY_HOST: host }
}
Expand Down

0 comments on commit 3cc8c31

Please sign in to comment.