lrj
4 小时以前 8337c34fcc761d07acaad796d10f3e12e9bbe2d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { graphqlRequest } from '../config/api.ts';
 
const GET_APP_CONFIG = `
  query AppConfig {
    appConfig {
      mediaBaseUrl
    }
  }
`;
 
export async function loadAppConfig() {
  try {
    const result = await graphqlRequest(GET_APP_CONFIG);
    const mediaBaseUrl = result.data?.appConfig?.mediaBaseUrl || '';
    // 作为全局变量暴露
    window.__APP_MEDIA_BASE_URL__ = mediaBaseUrl;
    return mediaBaseUrl;
  } catch (e) {
    // 如果GraphQL查询失败,使用默认配置
    console.warn('loadAppConfig failed, using default config:', e?.message || e);
    const defaultMediaBaseUrl = 'http://localhost:8080';
    window.__APP_MEDIA_BASE_URL__ = defaultMediaBaseUrl;
    return defaultMediaBaseUrl;
  }
}