From f64693c0da5483d8670220bf3a5bf89a32e94a20 Mon Sep 17 00:00:00 2001
From: peng <peng.com>
Date: 星期五, 07 十一月 2025 10:34:21 +0800
Subject: [PATCH] 解决线上打包问题
---
web/src/utils/appConfig.js | 47 ++++++++++++++++++++++++++++++++++++-----------
1 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/web/src/utils/appConfig.js b/web/src/utils/appConfig.js
index ebfb020..72b8a12 100644
--- a/web/src/utils/appConfig.js
+++ b/web/src/utils/appConfig.js
@@ -1,29 +1,54 @@
-const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql';
+import { graphqlRequest } from '../config/api.ts';
+
+export const serverUrl =
+ (typeof window !== 'undefined' && window.__APP_SERVER_URL__) ||
+ (typeof import.meta !== 'undefined' && import.meta.env && import.meta.env.VITE_SERVER_URL) ||
+ 'http://139.155.104.10:8080';
+
+
const GET_APP_CONFIG = `
+
query AppConfig {
+
appConfig {
+
mediaBaseUrl
+
}
+
}
+
`;
+
+
export async function loadAppConfig() {
+
try {
- const resp = await fetch(GRAPHQL_ENDPOINT, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ query: GET_APP_CONFIG })
- });
- const result = await resp.json();
- if (result.errors) throw new Error(result.errors[0]?.message || 'appConfig query failed');
+
+ const result = await graphqlRequest(GET_APP_CONFIG);
+
const mediaBaseUrl = result.data?.appConfig?.mediaBaseUrl || '';
+
// 浣滀负鍏ㄥ眬鍙橀噺鏆撮湶
+
window.__APP_MEDIA_BASE_URL__ = mediaBaseUrl;
+
return mediaBaseUrl;
+
} catch (e) {
- console.warn('loadAppConfig failed:', e?.message || e);
- window.__APP_MEDIA_BASE_URL__ = '';
- return '';
+
+ // 濡傛灉GraphQL鏌ヨ澶辫触锛屼娇鐢ㄩ粯璁ら厤缃�
+
+ console.warn('loadAppConfig failed, using default config:', e?.message || e);
+
+ const defaultMediaBaseUrl = serverUrl;
+
+ window.__APP_MEDIA_BASE_URL__ = defaultMediaBaseUrl;
+
+ return defaultMediaBaseUrl;
+
}
+
}
\ No newline at end of file
--
Gitblit v1.8.0