mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 17:53:44 +00:00
refactor: de-duplicate channel runtime and payload helpers
This commit is contained in:
45
src/shared/gateway-bind-url.ts
Normal file
45
src/shared/gateway-bind-url.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
export type GatewayBindUrlResult =
|
||||
| {
|
||||
url: string;
|
||||
source: "gateway.bind=custom" | "gateway.bind=tailnet" | "gateway.bind=lan";
|
||||
}
|
||||
| {
|
||||
error: string;
|
||||
}
|
||||
| null;
|
||||
|
||||
export function resolveGatewayBindUrl(params: {
|
||||
bind?: string;
|
||||
customBindHost?: string;
|
||||
scheme: "ws" | "wss";
|
||||
port: number;
|
||||
pickTailnetHost: () => string | null;
|
||||
pickLanHost: () => string | null;
|
||||
}): GatewayBindUrlResult {
|
||||
const bind = params.bind ?? "loopback";
|
||||
if (bind === "custom") {
|
||||
const host = params.customBindHost?.trim();
|
||||
if (host) {
|
||||
return { url: `${params.scheme}://${host}:${params.port}`, source: "gateway.bind=custom" };
|
||||
}
|
||||
return { error: "gateway.bind=custom requires gateway.customBindHost." };
|
||||
}
|
||||
|
||||
if (bind === "tailnet") {
|
||||
const host = params.pickTailnetHost();
|
||||
if (host) {
|
||||
return { url: `${params.scheme}://${host}:${params.port}`, source: "gateway.bind=tailnet" };
|
||||
}
|
||||
return { error: "gateway.bind=tailnet set, but no tailnet IP was found." };
|
||||
}
|
||||
|
||||
if (bind === "lan") {
|
||||
const host = params.pickLanHost();
|
||||
if (host) {
|
||||
return { url: `${params.scheme}://${host}:${params.port}`, source: "gateway.bind=lan" };
|
||||
}
|
||||
return { error: "gateway.bind=lan set, but no private LAN IP was found." };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user