fix: address onboarding review feedback

This commit is contained in:
Thomas Camlong authored and ajnart committed 2026-08-14 01:20:27 +02:00
1 parent 07770e862c
commit d89bf25e21
72 files changed
+7783 -280

No files matched your search

@@ -12,12 +12,18 @@ const normalizeBaseHost = (value: string) => {
const trimmed = value.trim();
if (!trimmed) return null;
try {
const parsed = new URL(trimmed.includes("://") ? trimmed : `http://${trimmed}`);
const url = trimmed.includes("://") ? trimmed : `http://${trimmed}`;
const authority = url
.match(/^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)/iu)?.[1]
?.split("@")
.at(-1);
const explicitPort = authority?.match(/^(?:\[[^\]]+\]|[^:]+):(\d+)$/u)?.[1];
const parsed = new URL(url);
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
return {
protocol: parsed.protocol,
hostname: parsed.hostname,
port: parsed.port ? Number(parsed.port) : undefined,
port: parsed.port ? Number(parsed.port) : explicitPort ? Number(explicitPort) : undefined,
pathname: parsed.pathname.replace(/\/+$/, ""),
};
} catch {
@@ -32,8 +38,7 @@ const buildUrl = (slug: string, rawHost: string, mode: UrlTemplateMode, port?: n
const modeBuilders: Record<UrlTemplateMode, () => string> = {
subdomain: () => (base.hostname.startsWith("[") ? "" : `https://${slug}.${base.hostname}`),
hostPort: () => (effectivePort ? `http://${base.hostname}:${effectivePort}` : `http://${base.hostname}`),
path: () =>
`${base.protocol}//${base.hostname}${base.port ? `:${base.port}` : ""}${base.pathname}/${slug}`,
path: () => `${base.protocol}//${base.hostname}${base.port ? `:${base.port}` : ""}${base.pathname}/${slug}`,
};
return modeBuilders[mode]();
};
@@ -38,9 +38,7 @@ describe("buildIntegrationUrl", () => {
expect(buildIntegrationUrl("sonarr", "https://home.example.com/services", "path")).toBe(
"https://home.example.com/services/sonarr",
);
expect(buildAppUrl("My Service", "home.lan/apps/", "path", 9999)).toBe(
"http://home.lan/apps/my-service",
);
expect(buildAppUrl("My Service", "home.lan/apps/", "path", 9999)).toBe("http://home.lan/apps/my-service");
});
it("replaces a supplied base port instead of producing a double port", () => {
@@ -52,6 +50,12 @@ describe("buildIntegrationUrl", () => {
);
});
it("preserves an explicitly supplied default port for an app", () => {
expect(buildAppUrl("My Service", "https://home.example.com:443/homarr", "hostPort")).toBe(
"http://home.example.com:443",
);
});
it("formats IPv6 hosts safely in host-port mode", () => {
expect(buildIntegrationUrl("sonarr", "https://[2001:db8::1]:8443/homarr", "hostPort")).toBe(
"http://[2001:db8::1]:8989",