From 50ae42087125859b22ac6b0deceecb98499e8ef9 Mon Sep 17 00:00:00 2001 From: chenhang Date: Tue, 16 Jun 2026 12:35:45 +0800 Subject: [PATCH] chore(config): add /ws path suffix to WebSocket URLs Update WebSocket base URLs across environment examples and default config to include the required `/ws` path suffix that the backend WebSocket endpoint expects. Applies to development, test/local, and production environments. --- env-example/.env.development.example | 3 ++- env-example/.env.local.example | 3 ++- env-example/.env.production.example | 5 +++-- src/core/net/config/api_config.ts | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/env-example/.env.development.example b/env-example/.env.development.example index 2cbeb856..7257f7d8 100644 --- a/env-example/.env.development.example +++ b/env-example/.env.development.example @@ -8,7 +8,8 @@ NEXTAUTH_URL=http://localhost:3000 NEXT_PUBLIC_API_BASE_URL=http://172.16.48.49:3002 # WebSocket URL(开发环境,可选) -NEXT_PUBLIC_WS_BASE_URL=ws://172.16.48.49:3002 +NEXT_PUBLIC_WS_BASE_URL=ws://172.16.48.49:3002/ws + # API 超时时间(毫秒) NEXT_PUBLIC_API_CONNECT_TIMEOUT=30000 diff --git a/env-example/.env.local.example b/env-example/.env.local.example index 280f189c..ca85ed09 100644 --- a/env-example/.env.local.example +++ b/env-example/.env.local.example @@ -4,7 +4,8 @@ NEXT_PUBLIC_APP_ENV=test NEXTAUTH_URL=https://frontend-test.banlv-ai.com NEXTAUTH_URL_INTERNAL=http://localhost:3000 NEXT_PUBLIC_API_BASE_URL=https://api.cozsweet.com -NEXT_PUBLIC_WS_BASE_URL=wss://api.cozsweet.com +NEXT_PUBLIC_WS_BASE_URL=wss://api.cozsweet.com/ws + NEXT_PUBLIC_API_CONNECT_TIMEOUT=30000 NEXT_PUBLIC_API_RECEIVE_TIMEOUT=60000 NEXT_PUBLIC_API_SEND_TIMEOUT=30000 diff --git a/env-example/.env.production.example b/env-example/.env.production.example index 0756335e..5e272cb0 100644 --- a/env-example/.env.production.example +++ b/env-example/.env.production.example @@ -8,8 +8,9 @@ NEXTAUTH_URL_INTERNAL=http://localhost:3000 # 后端 API 基础 URL(生产环境) NEXT_PUBLIC_API_BASE_URL=https://api.cozsweet.com -# WebSocket URL(生产环境,可选) -NEXT_PUBLIC_WS_BASE_URL=wss://api.cozsweet.com +# WebSocket URL(生产环境) +NEXT_PUBLIC_WS_BASE_URL=wss://api.cozsweet.com/ws + # API 超时时间(毫秒) NEXT_PUBLIC_API_CONNECT_TIMEOUT=30000 diff --git a/src/core/net/config/api_config.ts b/src/core/net/config/api_config.ts index a07ee6ed..dd1db524 100644 --- a/src/core/net/config/api_config.ts +++ b/src/core/net/config/api_config.ts @@ -45,7 +45,8 @@ export function getApiConfig(): ApiConfig { const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://172.16.48.49:3002"; const wsUrl = - process.env.NEXT_PUBLIC_WS_BASE_URL ?? "ws://172.16.48.49:3002"; + process.env.NEXT_PUBLIC_WS_BASE_URL ?? "ws://172.16.48.49:3002/ws"; + const connectTimeout = Number.parseInt( process.env.NEXT_PUBLIC_API_CONNECT_TIMEOUT ?? "30000", 10