use host header in middleware instead of nexturl.host

This commit is contained in:
Max Peintner
2025-01-16 10:48:26 +01:00
parent 5a1853a040
commit 827f38a4d8

View File

@@ -1,3 +1,4 @@
import { headers } from "next/headers";
import { NextRequest, NextResponse } from "next/server";
import { getInstanceUrl } from "./lib/api";
@@ -19,10 +20,16 @@ export async function middleware(request: NextRequest) {
// ) {
// return NextResponse.next();
// }
const _headers = await headers();
const _host = _headers.get("host");
console.log("host", _host);
const host = _host || request.nextUrl.host;
let instanceUrl;
try {
instanceUrl = await getInstanceUrl(request.nextUrl.host);
instanceUrl = await getInstanceUrl(host);
} catch (error) {
console.error(
"Could not get instance url, fallback to ZITADEL_API_URL",