Files
DecomEval/web/src/shared/base.ts
T

20 lines
742 B
TypeScript

function computeBase() {
const path = new URL(document.baseURI).pathname;
return path.endsWith("/") ? path : path.slice(0, path.lastIndexOf("/") + 1);
}
/** 站点所在路径,直接访问时是 "/",托管到平台时类似 "/apps/decomeval/"。 */
export const basePath = computeBase();
export function appUrl(path: string) {
return basePath + path.replace(/^\/+/, "");
}
export const platformHome = "/";
/** switchAccount 让平台先退出当前账号再显示登录表单,否则已登录的平台账号会被直接送回来。 */
export function platformLoginUrl(target = basePath, switchAccount = false) {
const url = `/login?redirect=${encodeURIComponent(target)}`;
return switchAccount ? `${url}&switch=1` : url;
}