Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions dev/prod/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import github, { githubId } from '@hcengineering/github'
import '@hcengineering/github-assets'

import { coreId } from '@hcengineering/core'
import presentation, { parsePreviewConfig, presentationId } from '@hcengineering/presentation'
import presentation, { loadServerConfig, parsePreviewConfig, presentationId } from '@hcengineering/presentation'

import { setMetadata } from '@hcengineering/platform'
import { setDefaultLanguage } from '@hcengineering/theme'
Expand Down Expand Up @@ -239,13 +239,12 @@ export async function configurePlatform() {
})
configureI18n()

const config: Config = await (await fetch(
const config: Config = await loadServerConfig(
devConfigHuly
? '/config-huly.json' : (
devConfigBold ? '/config-bold.json' : (
devConfig ? '/config-dev.json' : '/config.json'))
)
).json()
const branding: BrandingMap = config.BRANDING_URL !== undefined ? await (await fetch(config.BRANDING_URL)).json() : {}
const myBranding = branding[window.location.host] ?? {}

Expand Down
25 changes: 25 additions & 0 deletions packages/presentation/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,3 +693,28 @@ export function setDownloadProgress (percent: number): void {

upgradeDownloadProgress.set(Math.round(percent))
}

export async function loadServerConfig (url: string): Promise<any> {
let retries = 5
let res: Response | undefined

do {
try {
res = await fetch(url)
break
} catch (e: any) {
retries--
if (retries === 0) {
throw new Error(`Failed to load server config: ${e}`)
}
await new Promise((resolve) => setTimeout(resolve, 1000 * (5 - retries)))
}
} while (retries > 0)

if (res === undefined) {
// In theory should never get here
throw new Error('Failed to load server config')
}

return await res.json()
}
11 changes: 8 additions & 3 deletions plugins/guest-resources/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import core, {
} from '@hcengineering/core'
import login, { loginId } from '@hcengineering/login'
import { getMetadata, getResource, setMetadata } from '@hcengineering/platform'
import presentation, { closeClient, refreshClient, setClient, setPresentationCookie } from '@hcengineering/presentation'
import presentation, {
closeClient,
loadServerConfig,
refreshClient,
setClient,
setPresentationCookie
} from '@hcengineering/presentation'
import { fetchMetadataLocalStorage, getCurrentLocation, navigate, setMetadataLocalStorage } from '@hcengineering/ui'
import { writable } from 'svelte/store'

export const versionError = writable<string | undefined>(undefined)
const versionStorageKey = 'last_server_version'

Expand Down Expand Up @@ -113,7 +118,7 @@ export async function connect (title: string): Promise<Client | undefined> {
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? ''
const currentFrontVersion = getMetadata(presentation.metadata.FrontVersion)
if (currentFrontVersion !== undefined) {
const frontConfig = await (await fetch(concatLink(frontUrl, '/config.json'))).json()
const frontConfig = await loadServerConfig(concatLink(frontUrl, '/config.json'))
if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) {
location.reload()
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/workbench-resources/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import login, { loginId } from '@hcengineering/login'
import { broadcastEvent, getMetadata, getResource, setMetadata } from '@hcengineering/platform'
import presentation, {
closeClient,
loadServerConfig,
purgeClient,
refreshClient,
setClient,
Expand Down Expand Up @@ -221,7 +222,7 @@ export async function connect (title: string): Promise<Client | undefined> {
const frontUrl = getMetadata(presentation.metadata.FrontUrl) ?? ''
const currentFrontVersion = getMetadata(presentation.metadata.FrontVersion)
if (currentFrontVersion !== undefined) {
const frontConfig = await (await fetch(concatLink(frontUrl, '/config.json'))).json()
const frontConfig = await loadServerConfig(concatLink(frontUrl, '/config.json'))
if (frontConfig?.version !== undefined && frontConfig.version !== currentFrontVersion) {
location.reload()
}
Expand Down