mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-04 08:28:36 +00:00
fix(webui): honor custom gateway port with Vite (#5076)
This commit is contained in:
parent
5be176a6a0
commit
d3e4b35f2b
@ -116,7 +116,15 @@ export function deriveWsUrl(
|
|||||||
const host = window.location.hostname.includes(":")
|
const host = window.location.hostname.includes(":")
|
||||||
? `[${window.location.hostname}]`
|
? `[${window.location.hostname}]`
|
||||||
: window.location.hostname;
|
: window.location.hostname;
|
||||||
return `ws://${host}:8765${path}${query}`;
|
let scheme = "ws";
|
||||||
|
let port = "8765";
|
||||||
|
if (wsUrl && /^wss?:\/\//i.test(wsUrl)) {
|
||||||
|
const upstream = new URL(wsUrl);
|
||||||
|
scheme = upstream.protocol === "wss:" ? "wss" : "ws";
|
||||||
|
port = upstream.port;
|
||||||
|
}
|
||||||
|
const authority = port ? `${host}:${port}` : host;
|
||||||
|
return `${scheme}://${authority}${path}${query}`;
|
||||||
}
|
}
|
||||||
if (wsUrl && /^(wss?|nanobot-host):\/\//i.test(wsUrl)) {
|
if (wsUrl && /^(wss?|nanobot-host):\/\//i.test(wsUrl)) {
|
||||||
const join = wsUrl.includes("?") ? "&" : "?";
|
const join = wsUrl.includes("?") ? "&" : "?";
|
||||||
|
|||||||
@ -32,6 +32,19 @@ describe("bootstrap helpers", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("keeps the gateway websocket port when Vite proxies a custom target", () => {
|
||||||
|
vi.stubGlobal("window", {
|
||||||
|
location: {
|
||||||
|
port: "5173",
|
||||||
|
hostname: "127.0.0.1",
|
||||||
|
protocol: "http:",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(deriveWsUrl("/ws", "tok", "ws://127.0.0.1:8899/ws")).toBe(
|
||||||
|
"ws://127.0.0.1:8899/ws?token=tok",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("preserves the host socket bridge URL", () => {
|
it("preserves the host socket bridge URL", () => {
|
||||||
expect(deriveWsUrl("/", "tok en", "nanobot-host://engine/")).toBe(
|
expect(deriveWsUrl("/", "tok en", "nanobot-host://engine/")).toBe(
|
||||||
"nanobot-host://engine/?token=tok%20en",
|
"nanobot-host://engine/?token=tok%20en",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user