api to 8080 of localhost

This commit is contained in:
Max Peintner
2025-02-10 17:34:16 +01:00
parent 9851b6a72b
commit dcd73742f7
2 changed files with 8 additions and 4 deletions

View File

@@ -201,11 +201,13 @@ async function findValidSession(
}
function constructUrl(request: NextRequest, path: string) {
const forwardedHost = request.headers.get("host");
// TODO: remove localhost
const forwardedHost =
request.headers.get("x-zitadel-forward-host") ?? "http://localhost:8080";
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
return new URL(
`${basePath}${path}`,
forwardedHost?.startsWith("https://")
forwardedHost?.startsWith("http")
? forwardedHost
: `https://${forwardedHost}`,
);

View File

@@ -81,12 +81,14 @@ export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): {
} else if (process.env.ZITADEL_API_URL) {
instanceUrl = process.env.ZITADEL_API_URL;
} else {
const host = headers.get("host");
// TODO: remove this fallback once the host header is always set
const host =
headers.get("x-zitadel-forward-host") ?? "http://localhost:8080";
if (host) {
const [hostname, port] = host.split(":");
if (hostname !== "localhost") {
instanceUrl = host.startsWith("https://") ? host : `https://${host}`;
instanceUrl = host.startsWith("http") ? host : `https://${host}`;
}
}
}