Skip to content

Modern Docker Management, Designed for Everyone

fix: fix https links on containers list (#3191)

ribbald3c6bc985d83
diff --git a/frontend/src/lib/utils/navigation.ts b/frontend/src/lib/utils/navigation.ts
index 6eb525586..58da2bd8d 100644
--- a/frontend/src/lib/utils/navigation.ts
+++ b/frontend/src/lib/utils/navigation.ts
@@ -144,7 +144,10 @@ function getExpectedCode(key: string): string | null {
export function toPortHref(hostPort: string, baseServerUrl?: string): string {
try {
const base = baseServerUrl || (typeof window !== 'undefined' ? window.location.origin : 'http://localhost');
- const url = new URL(base.startsWith('http') ? base : `http://${base}`);
+ const scheme = hostPort.endsWith('443') ? 'https' : 'http';
+ const host = afterSubstring(base, "://");
+
+ const url = new URL(`${scheme}://${host}`);
url.port = hostPort;
return url.toString();
} catch {
@@ -152,6 +155,11 @@ export function toPortHref(hostPort: string, baseServerUrl?: string): string {
}
}
+function afterSubstring(text: string, search: string): string {
+ const index = text.indexOf(search);
+ return index === -1 ? text : text.slice(index + search.length);
+}
+
export function toSafeHref(raw: string, scheme: string = 'https'): string {
const trimmed = raw.trim();
if (!trimmed) return '#';