This commit is contained in:
parent
870e77efdf
commit
012e266a09
|
|
@ -182,16 +182,14 @@ export async function getWsBase() {
|
||||||
|
|
||||||
let wsProtocol = "ws";
|
let wsProtocol = "ws";
|
||||||
|
|
||||||
if (
|
if (typeof window !== "undefined") {
|
||||||
typeof window !== "undefined" &&
|
// ✅ 客户端环境(浏览器执行)
|
||||||
window.location &&
|
if (window.location.protocol === "https:") {
|
||||||
window.location.protocol === "https:"
|
wsProtocol = "wss";
|
||||||
) {
|
ip = window.location.hostname; // ✅ 用 hostname 避免 HTTPS + IP 的 TLS 报错
|
||||||
// ✅ 浏览器环境下
|
}
|
||||||
wsProtocol = "wss";
|
|
||||||
ip = window.location.hostname;
|
|
||||||
} else {
|
} else {
|
||||||
// ✅ 服务端环境,延迟导入 headers
|
// ✅ SSR 环境,延迟导入 headers(不能放顶层)
|
||||||
const { headers } = await import("next/headers");
|
const { headers } = await import("next/headers");
|
||||||
const hdrs = headers();
|
const hdrs = headers();
|
||||||
|
|
||||||
|
|
@ -203,14 +201,14 @@ export async function getWsBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostHeader) {
|
if (hostHeader) {
|
||||||
|
// ✅ host 可能带端口,需处理
|
||||||
ip = hostHeader.includes(":") ? hostHeader.split(":")[0] : hostHeader;
|
ip = hostHeader.includes(":") ? hostHeader.split(":")[0] : hostHeader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalUrl = `${wsProtocol}://${ip}/api/v1/deploy/ws`;
|
|
||||||
console.log(".........[WebSocket] Final URL:", finalUrl);
|
|
||||||
|
|
||||||
return `${wsProtocol}://${ip}/api/v1/deploy/ws`;
|
const finalUrl = `${wsProtocol}://${ip}/api/v1/deploy/ws`;
|
||||||
|
console.log("✅ [WebSocket] Final URL:", finalUrl);
|
||||||
|
return finalUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue