Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  url.ts

  Sprache: JAVA
 

import type { OpenClawConfig } from "../api.js";

const DEFAULT_GATEWAY_PORT = 18789;
type ViewerBaseUrlFieldName = "baseUrl" | "viewerBaseUrl";

export function buildViewerUrl(params: {
  config: OpenClawConfig;
  viewerPath: string;
  baseUrl?: string;
}): string {
  const baseUrl = params.baseUrl?.trim() || resolveGatewayBaseUrl(params.config);
  const normalizedBase = normalizeViewerBaseUrl(baseUrl);
  const viewerPath = params.viewerPath.startsWith("/")
    ? params.viewerPath
    : `/${params.viewerPath}`;
  const parsedBase = new URL(normalizedBase);
  const basePath = parsedBase.pathname === "/" ? "" : parsedBase.pathname.replace(/\/+$/, "");
  parsedBase.pathname = `${basePath}${viewerPath}`;
  parsedBase.search = "";
  parsedBase.hash = "";
  return parsedBase.toString();
}

export function normalizeViewerBaseUrl(
  raw: string,
  fieldName: ViewerBaseUrlFieldName = "baseUrl",
): string {
  let parsed: URL;
  try {
    parsed = new URL(raw);
  } catch {
    throw new Error(`Invalid ${fieldName}: ${raw}`);
  }
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
    throw new Error(`${fieldName} must use http or https: ${raw}`);
  }
  if (parsed.search || parsed.hash) {
    throw new Error(`${fieldName} must not include query/hash: ${raw}`);
  }
  parsed.search = "";
  parsed.hash = "";
  parsed.pathname = parsed.pathname.replace(/\/+$/, "");
  const withoutTrailingSlash = parsed.toString().replace(/\/+$/, "");
  return withoutTrailingSlash;
}

function resolveGatewayBaseUrl(config: OpenClawConfig): string {
  const scheme = config.gateway?.tls?.enabled ? "https" : "http";
  const port =
    typeof config.gateway?.port === "number" ? config.gateway.port : DEFAULT_GATEWAY_PORT;
  const customHost = config.gateway?.customBindHost?.trim();

  if (config.gateway?.bind === "custom" && customHost) {
    return `${scheme}://${customHost}:${port}`;
  }

  // Viewer links are used by local canvas/clients; default to loopback to avoid
  // container/bridge interfaces that are often unreachable from the caller.
  return `${scheme}://127.0.0.1:${port}`;
}

Messung V0.5 in Prozent
C=94 H=100 G=96

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-06-08) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik