From 7938e024215532a9caef3d3f1cfc38309e6c8ef8 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 7 Oct 2025 21:26:54 +0800 Subject: [PATCH] update --- .env | 3 ++- .env.production | 3 ++- .env.staging | 3 ++- .env.test | 3 ++- rsbuild.config.ts | 12 ++++-------- src/env.d.ts | 1 + src/shared/composables/websocket.ts | 4 +--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.env b/.env index a3a42f6..2538e06 100644 --- a/.env +++ b/.env @@ -3,4 +3,5 @@ PUBLIC_MAXKB_URL=https://maxkb.xuyue.cc/chat/api/embed?protocol=https&host=maxkb PUBLIC_OJ_URL=http://localhost:8000 PUBLIC_CODE_URL=http://localhost:3000 PUBLIC_JUDGE0_URL=https://judge0api.xuyue.cc -PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc \ No newline at end of file +PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc +PUBLIC_WS_URL=wss://oj.xuyue.cc/ws \ No newline at end of file diff --git a/.env.production b/.env.production index 6e5154d..00e306f 100644 --- a/.env.production +++ b/.env.production @@ -3,4 +3,5 @@ PUBLIC_MAXKB_URL=https://maxkb.xuyue.cc/chat/api/embed?protocol=https&host=maxkb PUBLIC_OJ_URL=https://oj.xuyue.cc PUBLIC_CODE_URL=https://code.xuyue.cc PUBLIC_JUDGE0_URL=https://judge0api.xuyue.cc -PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc \ No newline at end of file +PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc +PUBLIC_WS_URL=wss://oj.xuyue.cc/ws \ No newline at end of file diff --git a/.env.staging b/.env.staging index 580f9c8..c7201ee 100644 --- a/.env.staging +++ b/.env.staging @@ -4,4 +4,5 @@ PUBLIC_OJ_URL=http://10.13.114.114:81 PUBLIC_CODE_URL=http://10.13.114.114:82 PUBLIC_JUDGE0_URL=http://10.13.114.114:8082 PUBLIC_ICONIFY_URL=http://10.13.114.114:8098 -PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc \ No newline at end of file +PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc +PUBLIC_WS_URL=wss://oj.xuyue.cc/ws \ No newline at end of file diff --git a/.env.test b/.env.test index df21f23..dd5074c 100644 --- a/.env.test +++ b/.env.test @@ -4,4 +4,5 @@ PUBLIC_OJ_URL=http://10.13.114.114:81 PUBLIC_CODE_URL=http://10.13.114.114:82 PUBLIC_JUDGE0_URL=http://10.13.114.114:8082 PUBLIC_ICONIFY_URL=http://10.13.114.114:8098 -PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc \ No newline at end of file +PUBLIC_SIGNALING_URL=wss://signaling.xuyue.cc +PUBLIC_WS_URL=wss://oj.xuyue.cc/ws \ No newline at end of file diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 975e491..26c5d2b 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -10,19 +10,15 @@ export default defineConfig(({ envMode }) => { mode: envMode, }) - const url = rawPublicVars["PUBLIC_OJ_URL"] const proxyConfig = { - target: url, - headers: { Referer: url }, + target: rawPublicVars["PUBLIC_OJ_URL"], changeOrigin: true, } - // WebSocket 代理配置(开发环境 Daphne 在 8001 端口) const wsProxyConfig = { - target: url.replace(':8000', ':8001').replace('http:', 'ws:'), // http://localhost:8001 → ws://localhost:8001 - ws: true, // 启用 WebSocket 代理 + target: rawPublicVars["PUBLIC_WS_URL"], + ws: true, changeOrigin: true, - logLevel: 'debug' as const, // 显示代理日志 } return { plugins: [pluginVue()], @@ -149,7 +145,7 @@ export default defineConfig(({ envMode }) => { proxy: { "/api": proxyConfig, "/public": proxyConfig, - "/ws": wsProxyConfig, // WebSocket 使用单独的代理配置 + "/ws": wsProxyConfig, }, }, } diff --git a/src/env.d.ts b/src/env.d.ts index 4e48511..64a32cc 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -8,6 +8,7 @@ interface ImportMetaEnv { readonly PUBLIC_JUDGE0_URL: string readonly PUBLIC_ICONIFY_URL: string readonly PUBLIC_SIGNALING_URL: string + readonly PUBLIC_WS_URL: string } interface ImportMeta { diff --git a/src/shared/composables/websocket.ts b/src/shared/composables/websocket.ts index 53048c3..055f432 100644 --- a/src/shared/composables/websocket.ts +++ b/src/shared/composables/websocket.ts @@ -62,9 +62,7 @@ export class BaseWebSocket { public status: Ref = ref("disconnected") constructor(config: WebSocketConfig) { - const protocol = window.location.protocol === "https:" ? "wss:" : "ws:" - const host = window.location.host - this.url = `${protocol}//${host}/ws/${config.path}/` + this.url = import.meta.env.PUBLIC_WS_URL this.maxReconnectAttempts = config.maxReconnectAttempts ?? 5 this.reconnectDelay = config.reconnectDelay ?? 1000