feat(init): apply base URL template to discovered apps
Discovered Docker apps now use the same buildAppUrl logic as integrations when a base host is set, instead of using the raw Docker socket URL (e.g. http://container:5432). Extracts shared buildUrl helper and adds buildAppUrl that derives a slug from the container name. Also passes publishedPort through the DiscoveredApp type so host:port mode works correctly.
This commit is contained in:
1 parent
bbb04b084f
commit
7c0653672a
4 files changed
+36
-18
No files matched your search
@@ -36,6 +36,7 @@ export interface DiscoveredApp {
|
|||||||
containerId: string;
|
containerId: string;
|
||||||
containerName: string;
|
containerName: string;
|
||||||
suggestedUrl: string;
|
suggestedUrl: string;
|
||||||
|
publishedPort: number | null;
|
||||||
iconUrl: string | null;
|
iconUrl: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { IconArrowRight, IconInfoCircle, IconSettings } from "@tabler/icons-reac
|
|||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import type { IntegrationKind, UrlTemplateMode } from "@homarr/definitions";
|
import type { IntegrationKind, UrlTemplateMode } from "@homarr/definitions";
|
||||||
import { buildIntegrationUrl, getIntegrationName } from "@homarr/definitions";
|
import { buildAppUrl, buildIntegrationUrl, getIntegrationName } from "@homarr/definitions";
|
||||||
import { showErrorNotification } from "@homarr/notifications";
|
import { showErrorNotification } from "@homarr/notifications";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import { IntegrationAvatar } from "@homarr/ui";
|
import { IntegrationAvatar } from "@homarr/ui";
|
||||||
@@ -137,11 +137,16 @@ export const InitIntegrations = () => {
|
|||||||
const appsToCreate = dockerApps.filter((app) => selectedAppIds.has(app.containerId));
|
const appsToCreate = dockerApps.filter((app) => selectedAppIds.has(app.containerId));
|
||||||
if (appsToCreate.length > 0) {
|
if (appsToCreate.length > 0) {
|
||||||
await createApps(
|
await createApps(
|
||||||
appsToCreate.map((app) => ({
|
appsToCreate.map((app) => {
|
||||||
name: app.containerName,
|
const href = baseHost
|
||||||
href: app.suggestedUrl || null,
|
? buildAppUrl(app.containerName, baseHost, urlMode, app.publishedPort ?? undefined)
|
||||||
iconUrl: app.iconUrl,
|
: app.suggestedUrl;
|
||||||
})),
|
return {
|
||||||
|
name: app.containerName,
|
||||||
|
href: href || null,
|
||||||
|
iconUrl: app.iconUrl,
|
||||||
|
};
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await setupIntegrations();
|
await setupIntegrations();
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ export const onboardRouter = createTRPCRouter({
|
|||||||
containerId: string;
|
containerId: string;
|
||||||
containerName: string;
|
containerName: string;
|
||||||
suggestedUrl: string;
|
suggestedUrl: string;
|
||||||
|
publishedPort: number | null;
|
||||||
iconUrl: string | null;
|
iconUrl: string | null;
|
||||||
}[],
|
}[],
|
||||||
};
|
};
|
||||||
@@ -228,6 +229,7 @@ export const onboardRouter = createTRPCRouter({
|
|||||||
containerId: container.Id,
|
containerId: container.Id,
|
||||||
containerName,
|
containerName,
|
||||||
suggestedUrl,
|
suggestedUrl,
|
||||||
|
publishedPort,
|
||||||
iconUrl,
|
iconUrl,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ export type UrlTemplateMode = "hostPort" | "subdomain";
|
|||||||
|
|
||||||
const getSlugForKind = (kind: IntegrationKind): string => integrationIconSlugs[kind];
|
const getSlugForKind = (kind: IntegrationKind): string => integrationIconSlugs[kind];
|
||||||
|
|
||||||
|
const buildUrl = (slug: string, host: string, mode: UrlTemplateMode, port?: number): string => {
|
||||||
|
const modeBuilders: Record<UrlTemplateMode, () => string> = {
|
||||||
|
subdomain: () => `https://${slug}.${host}`,
|
||||||
|
hostPort: () => (port ? `http://${host}:${port}` : `http://${host}`),
|
||||||
|
};
|
||||||
|
return modeBuilders[mode]();
|
||||||
|
};
|
||||||
|
|
||||||
export const buildIntegrationUrl = (
|
export const buildIntegrationUrl = (
|
||||||
kind: IntegrationKind,
|
kind: IntegrationKind,
|
||||||
baseHost: string,
|
baseHost: string,
|
||||||
@@ -14,16 +22,18 @@ export const buildIntegrationUrl = (
|
|||||||
): string => {
|
): string => {
|
||||||
const host = baseHost.trim().replace(/\/+$/, "");
|
const host = baseHost.trim().replace(/\/+$/, "");
|
||||||
if (!host) return "";
|
if (!host) return "";
|
||||||
|
const port = dockerPort ?? getIntegrationDefaultPort(kind);
|
||||||
const slug = getSlugForKind(kind);
|
return buildUrl(getSlugForKind(kind), host, mode, port ?? undefined);
|
||||||
|
};
|
||||||
const modeBuilders: Record<UrlTemplateMode, () => string> = {
|
|
||||||
subdomain: () => `https://${slug}.${host}`,
|
export const buildAppUrl = (
|
||||||
hostPort: () => {
|
containerName: string,
|
||||||
const port = dockerPort ?? getIntegrationDefaultPort(kind);
|
baseHost: string,
|
||||||
return port ? `http://${host}:${port}` : `http://${host}`;
|
mode: UrlTemplateMode,
|
||||||
},
|
dockerPort?: number,
|
||||||
};
|
): string => {
|
||||||
|
const host = baseHost.trim().replace(/\/+$/, "");
|
||||||
return modeBuilders[mode]();
|
if (!host) return "";
|
||||||
|
const slug = containerName.toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
||||||
|
return buildUrl(slug, host, mode, dockerPort);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user