diff --git a/src/config/settings.ts b/src/config/settings.ts index 15ce17d..442ebc3 100644 --- a/src/config/settings.ts +++ b/src/config/settings.ts @@ -1,9 +1,15 @@ /** * 配置管理 - * 后端地址已预配置,用户无需手动设置 + * 支持 dev(本地开发)和 test(测试服务器)两种环境 */ import * as vscode from "vscode"; +/** 环境类型 */ +type Environment = "dev" | "test" | "prod"; + +/** 当前环境 - 修改这里切换环境 */ +const CURRENT_ENV: Environment = "dev"; + /** 配置项接口 */ export interface IccoderConfig { /** 后端服务地址 */ @@ -14,19 +20,40 @@ export interface IccoderConfig { userId: string; } -/** 默认配置(预配置,不暴露给用户) */ -const DEFAULT_CONFIG: IccoderConfig = { - backendUrl: "http://192.168.1.108:2233", - timeout: 60000, - userId: "default-user", +/** 环境配置 */ +const ENV_CONFIG: Record = { + /** 本地开发环境 */ + dev: { + backendUrl: "http://localhost:2233", + timeout: 60000, + userId: "default-user", + }, + /** 测试服务器环境 */ + test: { + backendUrl: "http://192.168.1.108:2233", + timeout: 60000, + userId: "default-user", + }, + /** 生产环境 */ + prod: { + backendUrl: "https://api.iccoder.com", // TODO: 替换为实际生产地址 + timeout: 60000, + userId: "default-user", + }, }; +/** + * 获取当前环境 + */ +export function getCurrentEnv(): Environment { + return CURRENT_ENV; +} + /** * 获取配置项 - * 直接返回预配置的值,用户无需手动配置 */ export function getConfig(): IccoderConfig { - return { ...DEFAULT_CONFIG }; + return { ...ENV_CONFIG[CURRENT_ENV] }; } /** @@ -34,7 +61,6 @@ export function getConfig(): IccoderConfig { */ export function getApiUrl(path: string): string { const { backendUrl } = getConfig(); - // 确保 URL 格式正确 const baseUrl = backendUrl.endsWith("/") ? backendUrl.slice(0, -1) : backendUrl;