diff --git a/src/main.ts b/src/main.ts index 03bbfe6..e12ee89 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,10 +40,17 @@ async function bootstrap() { logger: ['error', 'warn', 'log'], }); - // 允许前端后台(如Vite/React)跨域访问 + // 允许前端后台(如Vite/React)跨域访问,包括WebSocket app.enableCors({ - origin: true, + origin: [ + 'http://localhost:3000', + 'http://localhost:5173', // Vite默认端口 + 'https://whaletownend.xinghangee.icu', + /^https:\/\/.*\.xinghangee\.icu$/ + ], credentials: true, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With'], }); // 全局启用校验管道(核心配置)