feat: failover SuperAdmin domains for get_user/get_version
Replace nerkh.gold with adm.montzar/montech/montest and prefer last successful URL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+28
-6
@@ -325,28 +325,50 @@
|
||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||
}
|
||||
|
||||
function resolveTenantDomain() {
|
||||
var host = String(window.location.hostname || '').trim()
|
||||
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||
return 'k.montzar.ir'
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
function getSuperAdminBases() {
|
||||
return [
|
||||
'https://adm.montzar.ir',
|
||||
'https://adm.montech.ir',
|
||||
'https://adm.montest.ir'
|
||||
]
|
||||
}
|
||||
|
||||
function getVersionUrls() {
|
||||
var protocol = getProtocol()
|
||||
var domain = encodeURIComponent(resolveTenantDomain())
|
||||
var urls = getSuperAdminBases().map(function (base) {
|
||||
return base + '/get_version?domain=' + domain
|
||||
})
|
||||
|
||||
return [
|
||||
'https://nerkh.gold/get_version',
|
||||
return urls.concat([
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
protocol + '//212.23.201.173:8381/get_version',
|
||||
protocol + '//91.212.174.137:4040/server/get_version'
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
function getConfigUrls() {
|
||||
var protocol = getProtocol()
|
||||
var domain = encodeURIComponent(resolveTenantDomain())
|
||||
var urls = getSuperAdminBases().map(function (base) {
|
||||
return base + '/get_user?domain=' + domain
|
||||
})
|
||||
|
||||
return [
|
||||
protocol + '//nerkh.gold/get_user',
|
||||
return urls.concat([
|
||||
protocol + '//tablo.talasevin.ir/get_user',
|
||||
protocol + '//abshode-service.montgit.ir/server/get_user',
|
||||
protocol + '//212.23.201.173:8381/get_user',
|
||||
protocol + '//91.212.174.137:4040/server/get_user'
|
||||
]
|
||||
])
|
||||
}
|
||||
|
||||
function sortVersionUrls(urls) {
|
||||
|
||||
@@ -76,8 +76,8 @@ function resolveRemoteLogo(path: string) {
|
||||
|
||||
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
||||
const base = lastSuccess
|
||||
? lastSuccess.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
: 'https://nerkh.gold'
|
||||
? lastSuccess.replace(/[?#].*$/, '').replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
: 'https://adm.montzar.ir'
|
||||
|
||||
return `${base}/${path.replace(/^\/+/, '')}`
|
||||
}
|
||||
|
||||
+23
-10
@@ -5,30 +5,43 @@ import { readCachedAppConfig, writeCachedAppConfig } from '@/config/config-cache
|
||||
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||
export const CONFIG_RETRY_ROUNDS = 5
|
||||
|
||||
const SUPERADMIN_BASES = [
|
||||
'https://adm.montzar.ir',
|
||||
'https://adm.montech.ir',
|
||||
'https://adm.montest.ir',
|
||||
] as const
|
||||
|
||||
function getProtocol() {
|
||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
||||
}
|
||||
|
||||
function resolveTenantDomain() {
|
||||
const host = String(window.location.hostname || '').trim()
|
||||
if (!host || host === 'localhost' || host === '127.0.0.1') {
|
||||
return 'k.montzar.ir'
|
||||
}
|
||||
return host
|
||||
}
|
||||
|
||||
export function getConfigUrls() {
|
||||
const protocol = getProtocol()
|
||||
const domain = encodeURIComponent(resolveTenantDomain())
|
||||
|
||||
return [
|
||||
`${protocol}//nerkh.gold/get_user`,
|
||||
...SUPERADMIN_BASES.map((base) => `${base}/get_user?domain=${domain}`),
|
||||
`${protocol}//tablo.talasevin.ir/get_user`,
|
||||
`${protocol}//abshode-service.montgit.ir/server/get_user`,
|
||||
`${protocol}//212.23.201.173:8381/get_user`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_user`
|
||||
`${protocol}//91.212.174.137:4040/server/get_user`,
|
||||
]
|
||||
}
|
||||
|
||||
export function sortConfigUrls(urls: string[]) {
|
||||
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||
|
||||
return [...urls].sort((a, b) => {
|
||||
if (a === lastSuccessUrl) return -1
|
||||
if (b === lastSuccessUrl) return 1
|
||||
return 0
|
||||
})
|
||||
if (!lastSuccessUrl || !urls.includes(lastSuccessUrl)) {
|
||||
return [...urls]
|
||||
}
|
||||
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||
}
|
||||
|
||||
function clearStaleConfigSuccessUrl(url: string) {
|
||||
@@ -45,10 +58,10 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
Accept: 'application/json',
|
||||
},
|
||||
cache: 'no-store',
|
||||
signal: controller.signal
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -20,13 +20,19 @@ function getProtocol() {
|
||||
|
||||
function getVersionUrls() {
|
||||
const protocol = getProtocol()
|
||||
const host = String(window.location.hostname || '').trim()
|
||||
const domain = encodeURIComponent(
|
||||
!host || host === 'localhost' || host === '127.0.0.1' ? 'k.montzar.ir' : host,
|
||||
)
|
||||
|
||||
return [
|
||||
'https://nerkh.gold/get_version',
|
||||
`https://adm.montzar.ir/get_version?domain=${domain}`,
|
||||
`https://adm.montech.ir/get_version?domain=${domain}`,
|
||||
`https://adm.montest.ir/get_version?domain=${domain}`,
|
||||
'https://tablo.talasevin.ir/get_version',
|
||||
'https://abshode-service.montgit.ir/server/get_version',
|
||||
`${protocol}//212.23.201.173:8381/get_version`,
|
||||
`${protocol}//91.212.174.137:4040/server/get_version`
|
||||
`${protocol}//91.212.174.137:4040/server/get_version`,
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user