fix(api): enhance createWebSocketBaseUrl function to handle development environment and window context
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
const API_BASE_URL =
|
const API_BASE_URL =
|
||||||
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() || "http://127.0.0.1:8083"
|
process.env.NEXT_PUBLIC_API_BASE_URL?.trim() ||
|
||||||
|
(process.env.NODE_ENV === "development" ? "http://127.0.0.1:8083" : "")
|
||||||
|
|
||||||
export function createWebSocketBaseUrl() {
|
export function createWebSocketBaseUrl() {
|
||||||
return API_BASE_URL.replace(/^http/, "ws").replace(/\/$/, "")
|
if (API_BASE_URL) {
|
||||||
|
return API_BASE_URL.replace(/^http/, "ws").replace(/\/$/, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"
|
||||||
|
return `${protocol}//${window.location.host}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user