fix(gateway): advertise reachable canvas host
This commit is contained in:
@@ -3204,6 +3204,10 @@ export async function startGatewayServer(
|
|||||||
|
|
||||||
const machineDisplayName = await getMachineDisplayName();
|
const machineDisplayName = await getMachineDisplayName();
|
||||||
const canvasHostPortForBridge = canvasHostServer?.port;
|
const canvasHostPortForBridge = canvasHostServer?.port;
|
||||||
|
const canvasHostHostForBridge =
|
||||||
|
canvasHostServer && bridgeHost && bridgeHost !== "0.0.0.0" && bridgeHost !== "::"
|
||||||
|
? bridgeHost
|
||||||
|
: undefined;
|
||||||
|
|
||||||
if (bridgeEnabled && bridgePort > 0 && bridgeHost) {
|
if (bridgeEnabled && bridgePort > 0 && bridgeHost) {
|
||||||
try {
|
try {
|
||||||
@@ -3212,6 +3216,7 @@ export async function startGatewayServer(
|
|||||||
port: bridgePort,
|
port: bridgePort,
|
||||||
serverName: machineDisplayName,
|
serverName: machineDisplayName,
|
||||||
canvasHostPort: canvasHostPortForBridge,
|
canvasHostPort: canvasHostPortForBridge,
|
||||||
|
canvasHostHost: canvasHostHostForBridge,
|
||||||
onRequest: (nodeId, req) => handleBridgeRequest(nodeId, req),
|
onRequest: (nodeId, req) => handleBridgeRequest(nodeId, req),
|
||||||
onAuthenticated: async (node) => {
|
onAuthenticated: async (node) => {
|
||||||
const host = node.displayName?.trim() || node.nodeId;
|
const host = node.displayName?.trim() || node.nodeId;
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ export type NodeBridgeServerOpts = {
|
|||||||
port: number; // 0 = ephemeral
|
port: number; // 0 = ephemeral
|
||||||
pairingBaseDir?: string;
|
pairingBaseDir?: string;
|
||||||
canvasHostPort?: number;
|
canvasHostPort?: number;
|
||||||
|
canvasHostHost?: string;
|
||||||
onEvent?: (nodeId: string, evt: BridgeEventFrame) => Promise<void> | void;
|
onEvent?: (nodeId: string, evt: BridgeEventFrame) => Promise<void> | void;
|
||||||
onRequest?: (
|
onRequest?: (
|
||||||
nodeId: string,
|
nodeId: string,
|
||||||
@@ -187,10 +188,20 @@ export async function startNodeBridgeServer(
|
|||||||
? opts.serverName.trim()
|
? opts.serverName.trim()
|
||||||
: os.hostname();
|
: os.hostname();
|
||||||
|
|
||||||
|
const isLoopbackHost = (host: string) => {
|
||||||
|
const normalized = host.trim().toLowerCase();
|
||||||
|
if (normalized === "localhost") return true;
|
||||||
|
if (normalized === "::1") return true;
|
||||||
|
if (normalized === "0.0.0.0" || normalized === "::") return true;
|
||||||
|
return normalized.startsWith("127.");
|
||||||
|
};
|
||||||
|
|
||||||
const buildCanvasHostUrl = (socket: net.Socket) => {
|
const buildCanvasHostUrl = (socket: net.Socket) => {
|
||||||
const port = opts.canvasHostPort;
|
const port = opts.canvasHostPort;
|
||||||
if (!port) return undefined;
|
if (!port) return undefined;
|
||||||
const host = socket.localAddress?.trim();
|
const localHost = socket.localAddress?.trim() ?? "";
|
||||||
|
const override = opts.canvasHostHost?.trim() ?? "";
|
||||||
|
const host = !localHost || isLoopbackHost(localHost) ? override : localHost;
|
||||||
if (!host) return undefined;
|
if (!host) return undefined;
|
||||||
const formatted = host.includes(":") ? `[${host}]` : host;
|
const formatted = host.includes(":") ? `[${host}]` : host;
|
||||||
return `http://${formatted}:${port}`;
|
return `http://${formatted}:${port}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user