lrj
2 天以前 c61d4fe27c97d2ecc907756aa571a4ef14a7b9b6
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
26
27
28
29
const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql';
 
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 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 '';
  }
}