mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-16 06:52:08 +00:00
revert middleware
This commit is contained in:
@@ -1,41 +1,38 @@
|
||||
import type { NextRequest } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/.well-known/:path*",
|
||||
"/oauth/:path*",
|
||||
"/oidc/:path*",
|
||||
"/idps/callback/:path*",
|
||||
],
|
||||
};
|
||||
|
||||
const INSTANCE = process.env.ZITADEL_API_URL;
|
||||
const SERVICE_USER_ID = process.env.ZITADEL_SERVICE_USER_ID as string;
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
// OIDC specific routes
|
||||
if (
|
||||
request.nextUrl.pathname.startsWith("/.well-known") ||
|
||||
request.nextUrl.pathname.startsWith("/oauth") ||
|
||||
request.nextUrl.pathname.startsWith("/oidc") ||
|
||||
request.nextUrl.pathname.startsWith("/idps/callback")
|
||||
) {
|
||||
const requestHeaders = new Headers(request.headers);
|
||||
requestHeaders.set("x-zitadel-login-client", SERVICE_USER_ID);
|
||||
const requestHeaders = new Headers(request.headers);
|
||||
requestHeaders.set("x-zitadel-login-client", SERVICE_USER_ID);
|
||||
|
||||
// this is a workaround for the next.js server not forwarding the host header
|
||||
// requestHeaders.set("x-zitadel-forwarded", `host="${request.nextUrl.host}"`);
|
||||
requestHeaders.set("x-zitadel-public-host", `${request.nextUrl.host}`);
|
||||
// this is a workaround for the next.js server not forwarding the host header
|
||||
// requestHeaders.set("x-zitadel-forwarded", `host="${request.nextUrl.host}"`);
|
||||
requestHeaders.set("x-zitadel-public-host", `${request.nextUrl.host}`);
|
||||
|
||||
// this is a workaround for the next.js server not forwarding the host header
|
||||
requestHeaders.set(
|
||||
"x-zitadel-instance-host",
|
||||
`${INSTANCE}`.replace("https://", ""),
|
||||
);
|
||||
// this is a workaround for the next.js server not forwarding the host header
|
||||
requestHeaders.set(
|
||||
"x-zitadel-instance-host",
|
||||
`${INSTANCE}`.replace("https://", ""),
|
||||
);
|
||||
|
||||
const responseHeaders = new Headers();
|
||||
responseHeaders.set("Access-Control-Allow-Origin", "*");
|
||||
responseHeaders.set("Access-Control-Allow-Headers", "*");
|
||||
const responseHeaders = new Headers();
|
||||
responseHeaders.set("Access-Control-Allow-Origin", "*");
|
||||
responseHeaders.set("Access-Control-Allow-Headers", "*");
|
||||
|
||||
request.nextUrl.href = `${INSTANCE}${request.nextUrl.pathname}${request.nextUrl.search}`;
|
||||
|
||||
return NextResponse.rewrite(request.nextUrl, {
|
||||
request: {
|
||||
headers: requestHeaders,
|
||||
},
|
||||
headers: responseHeaders,
|
||||
});
|
||||
}
|
||||
request.nextUrl.href = `${INSTANCE}${request.nextUrl.pathname}${request.nextUrl.search}`;
|
||||
return NextResponse.rewrite(request.nextUrl, {
|
||||
request: {
|
||||
headers: requestHeaders,
|
||||
},
|
||||
headers: responseHeaders,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user