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:'
|
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() {
|
function getVersionUrls() {
|
||||||
var protocol = getProtocol()
|
var protocol = getProtocol()
|
||||||
|
var domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
var urls = getSuperAdminBases().map(function (base) {
|
||||||
|
return base + '/get_version?domain=' + domain
|
||||||
|
})
|
||||||
|
|
||||||
return [
|
return urls.concat([
|
||||||
'https://nerkh.gold/get_version',
|
|
||||||
'https://tablo.talasevin.ir/get_version',
|
'https://tablo.talasevin.ir/get_version',
|
||||||
'https://abshode-service.montgit.ir/server/get_version',
|
'https://abshode-service.montgit.ir/server/get_version',
|
||||||
protocol + '//212.23.201.173:8381/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'
|
||||||
]
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConfigUrls() {
|
function getConfigUrls() {
|
||||||
var protocol = getProtocol()
|
var protocol = getProtocol()
|
||||||
|
var domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
var urls = getSuperAdminBases().map(function (base) {
|
||||||
|
return base + '/get_user?domain=' + domain
|
||||||
|
})
|
||||||
|
|
||||||
return [
|
return urls.concat([
|
||||||
protocol + '//nerkh.gold/get_user',
|
|
||||||
protocol + '//tablo.talasevin.ir/get_user',
|
protocol + '//tablo.talasevin.ir/get_user',
|
||||||
protocol + '//abshode-service.montgit.ir/server/get_user',
|
protocol + '//abshode-service.montgit.ir/server/get_user',
|
||||||
protocol + '//212.23.201.173:8381/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'
|
||||||
]
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortVersionUrls(urls) {
|
function sortVersionUrls(urls) {
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ function resolveRemoteLogo(path: string) {
|
|||||||
|
|
||||||
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
const lastSuccess = localStorage.getItem('CONFIG_Success_URL')
|
||||||
const base = lastSuccess
|
const base = lastSuccess
|
||||||
? lastSuccess.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
? lastSuccess.replace(/[?#].*$/, '').replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||||
: 'https://nerkh.gold'
|
: 'https://adm.montzar.ir'
|
||||||
|
|
||||||
return `${base}/${path.replace(/^\/+/, '')}`
|
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'
|
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||||
export const CONFIG_RETRY_ROUNDS = 5
|
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() {
|
function getProtocol() {
|
||||||
return window.location.protocol === 'https:' ? 'https:' : 'http:'
|
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() {
|
export function getConfigUrls() {
|
||||||
const protocol = getProtocol()
|
const protocol = getProtocol()
|
||||||
|
const domain = encodeURIComponent(resolveTenantDomain())
|
||||||
|
|
||||||
return [
|
return [
|
||||||
`${protocol}//nerkh.gold/get_user`,
|
...SUPERADMIN_BASES.map((base) => `${base}/get_user?domain=${domain}`),
|
||||||
`${protocol}//tablo.talasevin.ir/get_user`,
|
`${protocol}//tablo.talasevin.ir/get_user`,
|
||||||
`${protocol}//abshode-service.montgit.ir/server/get_user`,
|
`${protocol}//abshode-service.montgit.ir/server/get_user`,
|
||||||
`${protocol}//212.23.201.173:8381/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[]) {
|
export function sortConfigUrls(urls: string[]) {
|
||||||
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
const lastSuccessUrl = localStorage.getItem(CONFIG_SUCCESS_URL_KEY)
|
||||||
|
if (!lastSuccessUrl || !urls.includes(lastSuccessUrl)) {
|
||||||
return [...urls].sort((a, b) => {
|
return [...urls]
|
||||||
if (a === lastSuccessUrl) return -1
|
}
|
||||||
if (b === lastSuccessUrl) return 1
|
return [lastSuccessUrl, ...urls.filter((url) => url !== lastSuccessUrl)]
|
||||||
return 0
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearStaleConfigSuccessUrl(url: string) {
|
function clearStaleConfigSuccessUrl(url: string) {
|
||||||
@@ -45,10 +58,10 @@ async function fetchConfig(url: string, timeout = 3000): Promise<AppConfig> {
|
|||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/json'
|
Accept: 'application/json',
|
||||||
},
|
},
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
signal: controller.signal
|
signal: controller.signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -20,13 +20,19 @@ function getProtocol() {
|
|||||||
|
|
||||||
function getVersionUrls() {
|
function getVersionUrls() {
|
||||||
const protocol = getProtocol()
|
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 [
|
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://tablo.talasevin.ir/get_version',
|
||||||
'https://abshode-service.montgit.ir/server/get_version',
|
'https://abshode-service.montgit.ir/server/get_version',
|
||||||
`${protocol}//212.23.201.173:8381/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