Update terminal panel

This commit is contained in:
MacRimi
2026-03-15 16:27:37 +01:00
parent 65add36b2f
commit 0d6d570ae8
4 changed files with 56 additions and 48 deletions

View File

@@ -50,41 +50,6 @@ export function getApiUrl(endpoint: string): string {
return `${baseUrl}${normalizedEndpoint}`
}
/**
* Gets the base URL for WebSocket connections
* Automatically handles ws:// vs wss:// based on page protocol (SSL support)
*
* @param path - WebSocket endpoint path (e.g., '/ws/terminal')
* @returns Full WebSocket URL
*/
export function getWebSocketUrl(path: string): string {
if (typeof window === "undefined") {
return `ws://localhost:${API_PORT}${path}`
}
const { protocol, hostname, port } = window.location
const isStandardPort = port === "" || port === "80" || port === "443"
// Use wss:// when page is served over https://
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
// Ensure path starts with /
const normalizedPath = path.startsWith("/") ? path : `/${path}`
let wsUrl: string
if (isStandardPort) {
// Behind a proxy - WebSocket goes through same host
wsUrl = `${wsProtocol}//${hostname}${normalizedPath}`
} else {
// Direct access - use API port
wsUrl = `${wsProtocol}//${hostname}:${API_PORT}${normalizedPath}`
}
console.log(`[v0] getWebSocketUrl: protocol=${protocol}, hostname=${hostname}, port=${port}, isStandardPort=${isStandardPort}, wsUrl=${wsUrl}`)
return wsUrl
}
/**
* Gets the JWT token from localStorage
*