speakingApiConfig.ts 912 B

123456789101112131415161718
  1. export const FALLBACK_SPEAKING_API_HOST = 'https://ppt-english-speaking-api.cocorobo.cn'
  2. const ENV_SPEAKING_API_HOST = import.meta.env.VITE_SPEAKING_API_HOST?.trim()
  3. const SPEAKING_API_HOST = (ENV_SPEAKING_API_HOST || FALLBACK_SPEAKING_API_HOST).replace(/\/+$/, '')
  4. export const SPEAKING_DIALOGUE_API_BASE_URL = `${SPEAKING_API_HOST}/api/speaking/dialogue`
  5. export const SPEAKING_CONFIG_API_BASE_URL = `${SPEAKING_API_HOST}/api/speaking/config`
  6. export type SpeakTransport = 'websocket' | 'http'
  7. const ENV_SPEAKING_TRANSPORT = import.meta.env.VITE_SPEAKING_TRANSPORT?.trim().toLowerCase()
  8. export const SPEAKING_TRANSPORT: SpeakTransport = ENV_SPEAKING_TRANSPORT === 'http' ? 'http' : 'websocket'
  9. export function buildSpeakingWsUrl(path: string): string {
  10. const normalizedPath = path.startsWith('/') ? path : `/${path}`
  11. return `${SPEAKING_DIALOGUE_API_BASE_URL.replace(/^http/, 'ws')}${normalizedPath}`
  12. }