diff --git a/persona-studio/backend/server.js b/persona-studio/backend/server.js index f8c4ea12..ae561b8f 100644 --- a/persona-studio/backend/server.js +++ b/persona-studio/backend/server.js @@ -12,7 +12,17 @@ const apikeyRoutes = require('./routes/apikey'); const previewRoutes = require('./routes/preview'); const app = express(); -app.use(cors()); +app.use(cors({ + origin: [ + 'http://localhost:3002', + 'http://127.0.0.1:3002', + 'http://8.155.62.235', + 'https://guanghulab.com', + 'http://guanghulab.com', + 'https://qinfendebingshuo.github.io' + ], + credentials: true +})); app.use(express.json({ limit: '2mb' })); // ── 静态文件:persona-studio 前端 ── diff --git a/persona-studio/frontend/chat.js b/persona-studio/frontend/chat.js index 05158e9f..b4a38bf7 100644 --- a/persona-studio/frontend/chat.js +++ b/persona-studio/frontend/chat.js @@ -15,7 +15,8 @@ const API_BASE = (function () { if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') { return 'http://localhost:3002'; } - return 'https://guanghulab.com'; + // 非本地环境统一使用当前域名 + 协议,走 Nginx 转发 + return location.protocol + '//' + location.host; })(); /* ---- State ---- */ diff --git a/persona-studio/frontend/index.html b/persona-studio/frontend/index.html index 1835efe8..d9299f13 100644 --- a/persona-studio/frontend/index.html +++ b/persona-studio/frontend/index.html @@ -152,7 +152,8 @@ if (location.hostname === 'localhost' || location.hostname === '127.0.0.1') { return 'http://localhost:3002'; } - return 'https://guanghulab.com'; + // 非本地环境统一使用当前域名 + 协议,走 Nginx 转发 + return location.protocol + '//' + location.host; } function normalizeApiBase(base) {