You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { createApp } from "vue";
|
|
import App from "./App.vue";
|
|
import "./assets/main.css";
|
|
import { getAllConfig } from "./host/config";
|
|
import { getServerIpFromConfig } from "./utils/noticeConfig";
|
|
import { applyServerIpToHttp } from "./utils/service";
|
|
import { loadNoticeVideoListOnOpen } from "./api/notice";
|
|
import { router } from "./router";
|
|
import { log } from "./host/logger";
|
|
|
|
function withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T> {
|
|
return new Promise<T>((resolve, reject) => {
|
|
const timer = setTimeout(() => {
|
|
reject(new Error(`timeout after ${timeoutMs}ms`));
|
|
}, timeoutMs);
|
|
|
|
promise
|
|
.then((value) => {
|
|
clearTimeout(timer);
|
|
resolve(value);
|
|
})
|
|
.catch((error) => {
|
|
clearTimeout(timer);
|
|
reject(error);
|
|
});
|
|
});
|
|
}
|
|
|
|
async function bootstrap(): Promise<void> {
|
|
try {
|
|
const config = await withTimeout(getAllConfig(), 1500);
|
|
const serverIp = getServerIpFromConfig(config);
|
|
if (serverIp) {
|
|
applyServerIpToHttp(serverIp);
|
|
void loadNoticeVideoListOnOpen().catch(async (error) => {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
await log("warn", `启动时拉取 videolist 失败: ${message}`);
|
|
});
|
|
}
|
|
} catch {
|
|
// 配置缺失时由路由守卫引导到设置页
|
|
}
|
|
|
|
const app = createApp(App);
|
|
app.use(router).mount("#app");
|
|
}
|
|
|
|
void bootstrap();
|