feat(framework): config 生产用 HttpConfigFetcher(全局 fetch)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
import type { ConfigFetcher, RemoteConfig } from './remote-config.ts';
|
||||||
|
import { ConfigParseError } from './remote-config.ts';
|
||||||
|
|
||||||
|
/** 生产用 ConfigFetcher:全局 fetch 抓取远程配置 txt 并 JSON.parse。 */
|
||||||
|
export class HttpConfigFetcher implements ConfigFetcher {
|
||||||
|
async fetch(url: string): Promise<RemoteConfig> {
|
||||||
|
const resp = await fetch(url, { method: 'GET' });
|
||||||
|
const text = await resp.text();
|
||||||
|
try {
|
||||||
|
return JSON.parse(text) as RemoteConfig;
|
||||||
|
} catch {
|
||||||
|
throw new ConfigParseError(`远程配置 JSON 解析失败: ${url}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user