mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-22 11:01:54 +03:00
Retry for load of config.json (#6397)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
parent
0f56185730
commit
7324f2ef54
@ -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'
|
||||
@ -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] ?? {}
|
||||
|
||||
|
@ -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,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'
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user