Files
project57-x/src/main.ts
T
mdszxy fe18e608dc
CI Pipeline / check-commit (push) Successful in 7s
CI Pipeline / deploy-only (push) Has been skipped
CI Pipeline / build (push) Successful in 27s
CI Pipeline / deploy (push) Failing after 2s
feat: proxy embed assets to in-cluster project57 [deploy]
2026-10-05 17:42:36 +08:00

64 lines
1.5 KiB
TypeScript

const errorEl = document.getElementById("aurora-error");
function showError(message: string) {
if (!errorEl) return;
errorEl.style.display = "block";
errorEl.textContent = message;
}
function loadScript(src: string): Promise<void> {
return new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = src;
script.async = true;
script.onload = () => resolve();
script.onerror = () => reject(new Error(`无法加载 ${src}`));
document.head.appendChild(script);
});
}
async function boot() {
const origin = window.location.origin;
try {
await loadScript(`${origin}/embed/aurora.js?v=1`);
} catch {
showError(
`无法加载前台脚本:${origin}/embed/aurora.js。请确认 B 站已反代到 A 站,且 A 站已部署 embed 产物。`
);
return;
}
const api = window.AuroraSite;
if (!api?.mount) {
showError("脚本已加载,但未找到 AuroraSite.mount。");
return;
}
api.mount("#aurora-root", {
assetBase: origin,
apiBase: origin,
cssUrl: `${origin}/embed/aurora.css?v=1`,
history: "hash",
});
}
boot();
declare global {
interface Window {
AuroraSite?: {
mount: (
target: string | Element,
options?: {
assetBase?: string;
apiBase?: string;
cssUrl?: string;
history?: "hash" | "browser";
basename?: string;
}
) => { unmount: () => void };
};
}
}