| | |
| | | const GRAPHQL_ENDPOINT = '/api/graphql'; |
| | | import { graphqlRequest } from '../config/api.ts'; |
| | | |
| | | const GET_APP_CONFIG = ` |
| | | query AppConfig { |
| | |
| | | |
| | | 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 = 'http://localhost:8080'; |
| | | window.__APP_MEDIA_BASE_URL__ = defaultMediaBaseUrl; |
| | | return defaultMediaBaseUrl; |
| | | } |
| | | } |