/**
* 外部 API 统一走本地代理,避免浏览器 CORS / 网络拦截导致 Failed to fetch。
* 代理配置见 vite.config.ts
*/
export const API = {
frankfurter: '/api/frankfurter',
openMeteo: '/api/open-meteo',
geocoding: '/api/geocoding',
} as const
export async function proxyFetch(url: string, label: string): Promise<Response> {
try {
const res = await fetch(url)
return res
} catch (err) {
const msg = err instanceof Error ? err.message : String(err)
throw new Error(`${label} 网络请求失败(${msg})。请确认已运行 npm run dev 且勿开启干扰代理的 VPN。`)
}
}