Files
tyapi-frontend/src/constants/portal.js
2026-04-25 11:59:14 +08:00

28 lines
983 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 子账号注册/登录为 /sub/auth/*与主站同前端VITE_IS_SUB_PORTAL=true 时仅多一层「根进子账号登录 + 侧栏子账号壳」
*/
export const isSubPortal = import.meta.env.VITE_IS_SUB_PORTAL === 'true'
const trimTrailingSlash = (value = '') => value.replace(/\/+$/, '')
export const subPortalBaseURL = trimTrailingSlash(import.meta.env.VITE_SUB_PORTAL_BASE_URL || '')
export const mainPortalBaseURL = trimTrailingSlash(import.meta.env.VITE_MAIN_PORTAL_BASE_URL || '')
const getOrigin = (url) => {
if (!url) return ''
try {
return new URL(url).origin
} catch {
return ''
}
}
export const subPortalOrigin = getOrigin(subPortalBaseURL)
export const mainPortalOrigin = getOrigin(mainPortalBaseURL)
export const isPortalDomainConfigReady = Boolean(subPortalOrigin && mainPortalOrigin)
export const isCurrentOrigin = (origin) => {
if (!origin || typeof window === 'undefined') return false
return window.location.origin === origin
}