24 lines
853 B
TypeScript
24 lines
853 B
TypeScript
const DEFAULT_ADMIN_BASE_PATH = '/admin'
|
|
|
|
function normalizeAdminBasePath(value: string | undefined) {
|
|
const raw = (value || DEFAULT_ADMIN_BASE_PATH).trim()
|
|
if (!raw || raw === '/') return DEFAULT_ADMIN_BASE_PATH
|
|
const withLeadingSlash = raw.startsWith('/') ? raw : `/${raw}`
|
|
return withLeadingSlash.replace(/\/+$/, '') || DEFAULT_ADMIN_BASE_PATH
|
|
}
|
|
|
|
export const ADMIN_BASE_PATH = normalizeAdminBasePath(import.meta.env.VITE_ADMIN_BASE_PATH)
|
|
|
|
export function adminPath(path = '') {
|
|
const suffix = path.trim().replace(/^\/+/, '')
|
|
if (!suffix) return ADMIN_BASE_PATH
|
|
return `${ADMIN_BASE_PATH}/${suffix}`
|
|
}
|
|
|
|
export const ADMIN_LOGIN_PATH = adminPath('login')
|
|
export const ADMIN_DASHBOARD_PATH = adminPath('dashboard')
|
|
|
|
export function isAdminPath(path: string) {
|
|
return path === ADMIN_BASE_PATH || path.startsWith(`${ADMIN_BASE_PATH}/`)
|
|
}
|