diff --git a/.env.example b/.env.example index 755069b..80cf28d 100644 --- a/.env.example +++ b/.env.example @@ -9,12 +9,12 @@ VITE_FILE_SERVER=https://your-file-server.com # AI 网关(OpenAI兼容) # - 开发环境推荐走同源反代:VITE_AI_API_URL=/ai-proxy(配合 vite.config.ts) # - 生产环境可直连(需 AI 服务允许 CORS),或在 Nginx 里配置 /ai-proxy 反代 -VITE_AI_API_URL=http://127.0.0.1:11434/api/v1 +VITE_AI_API_URL=/ai-proxy # Ollama 原生接口(默认端口 11434) # - 开发环境推荐走同源反代:VITE_OLLAMA_API_URL=/proxy(配合 vite.config.ts) # - 生产环境不要直接用 http(会混合内容被拦截),建议 Nginx 反代成同源 https -VITE_OLLAMA_API_URL=http://127.0.0.1:11434 +VITE_OLLAMA_API_URL=/proxy # 仅用于本地开发反代注入(vite.config.ts 会读取并注入到 /ai-proxy 请求头) # 不要加 VITE_ 前缀,避免被打包到前端产物里 diff --git a/src/config/setting.ts b/src/config/setting.ts index 0d6337f..4731888 100644 --- a/src/config/setting.ts +++ b/src/config/setting.ts @@ -20,7 +20,7 @@ export const FILE_SERVER = export const AI_API_URL = import.meta.env.VITE_AI_API_URL || // Prefer same-origin reverse proxy during local development to avoid CORS. - (import.meta.env.DEV ? '/ai-proxy' : 'http://127.0.0.1:11434/api/v1'); + (import.meta.env.DEV ? '/ai-proxy' : 'https://ai-api.websoft.top/api/v1'); // Ollama native API endpoint (usually http://host:11434). // Note: browsers cannot call http from an https site (mixed-content); prefer same-origin proxy. diff --git a/src/views/ai/index.vue b/src/views/ai/index.vue index a13e9f9..a200cf4 100644 --- a/src/views/ai/index.vue +++ b/src/views/ai/index.vue @@ -12,9 +12,12 @@ // Hardcode endpoint to avoid going through mp.websoft.top `/proxy`. // The API methods append `/api/*` paths. - const BASE_URL = import.meta.env.PROD - ? 'http://127.0.0.1:11434' - : 'https://ai-api.websoft.top'; + // + // IMPORTANT: do not use `127.0.0.1` in browser production builds: + // it points to the visitor's machine, not your server. + // If you want to use server-local Ollama (`127.0.0.1:11434`), put it behind an HTTPS reverse proxy + // (e.g. `https://ai-api.websoft.top` or same-origin `/proxy`). + const BASE_URL = 'https://ai-api.websoft.top'; const modelLoading = ref(false); const models = ref>([]);