fix(web): derive WebSocket URL from browser location instead of backend (#2405)
The frontend previously used ws_url returned by /api/pico/token, which is built from the launcher's own port. Behind a reverse proxy this can produce incorrect URLs (e.g. ws://localhost:18800 instead of the proxy's public address). Since the launcher already proxies /pico/ws on the same port, the frontend can simply use window.location.host to construct the WebSocket URL, which is always correct regardless of proxy layers. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7bf6cbe1fa
commit
6a8552a664
1 changed files with 4 additions and 4 deletions
|
|
@ -15,7 +15,6 @@ import {
|
||||||
import {
|
import {
|
||||||
invalidateSocket,
|
invalidateSocket,
|
||||||
isCurrentSocket,
|
isCurrentSocket,
|
||||||
normalizeWsUrlForBrowser,
|
|
||||||
} from "@/features/chat/websocket"
|
} from "@/features/chat/websocket"
|
||||||
import i18n from "@/i18n"
|
import i18n from "@/i18n"
|
||||||
import {
|
import {
|
||||||
|
|
@ -135,7 +134,7 @@ export async function connectChat() {
|
||||||
updateChatStore({ connectionState: "connecting" })
|
updateChatStore({ connectionState: "connecting" })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { token, ws_url } = await getPicoToken()
|
const { token } = await getPicoToken()
|
||||||
const sessionId = activeSessionIdRef
|
const sessionId = activeSessionIdRef
|
||||||
|
|
||||||
if (generation !== connectionGeneration) {
|
if (generation !== connectionGeneration) {
|
||||||
|
|
@ -151,8 +150,9 @@ export async function connectChat() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalWsUrl = normalizeWsUrlForBrowser(ws_url)
|
const wsScheme = window.location.protocol === "https:" ? "wss:" : "ws:"
|
||||||
const url = `${finalWsUrl}?session_id=${encodeURIComponent(sessionId)}`
|
const wsUrl = `${wsScheme}//${window.location.host}/pico/ws`
|
||||||
|
const url = `${wsUrl}?session_id=${encodeURIComponent(sessionId)}`
|
||||||
const socket = new WebSocket(url, [`token.${token}`])
|
const socket = new WebSocket(url, [`token.${token}`])
|
||||||
|
|
||||||
if (generation !== connectionGeneration) {
|
if (generation !== connectionGeneration) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue