Fix outpost upstream dial address parsing

The outpost upstream was being passed directly to Caddy's dial field with the
full URL (http://host:port), but Caddy expects just host:port. This was causing
DNS lookup errors with a leading slash (/authentik.bologna.local.fuo.fi).

Now properly parses the URL to extract just the hostname and port.
This commit is contained in:
fuomag9
2025-11-19 20:22:38 +01:00
parent b2183bf856
commit 454edba677
+12 -1
View File
@@ -359,11 +359,22 @@ function buildProxyRoutes(
// Authentik outpost handler will be added later after protected paths
let outpostRoute: CaddyHttpRoute | null = null;
if (authentik) {
// Parse the outpost upstream URL to extract host:port for Caddy's dial field
let outpostDial = authentik.outpostUpstream;
try {
const url = new URL(authentik.outpostUpstream);
const port = url.port || (url.protocol === "https:" ? "443" : "80");
outpostDial = `${url.hostname}:${port}`;
} catch {
// If URL parsing fails, try to extract host:port from string
outpostDial = authentik.outpostUpstream.replace(/^https?:\/\//, "").replace(/\/$/, "");
}
const outpostHandler: Record<string, unknown> = {
handler: "reverse_proxy",
upstreams: [
{
dial: authentik.outpostUpstream
dial: outpostDial
}
]
};