2023-08-18 10:46:13 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import type { NextRequest } from "next/server";
|
|
|
|
|
|
|
|
|
|
export const config = {
|
|
|
|
|
matcher: ["/.well-known/:path*", "/oauth/:path*", "/oidc/: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) {
|
2023-09-27 09:02:46 +02:00
|
|
|
const requestHeaders = new Headers();
|
2023-08-18 10:46:13 +02:00
|
|
|
requestHeaders.set("x-zitadel-login-client", SERVICE_USER_ID);
|
|
|
|
|
|
2023-09-27 09:01:25 +02:00
|
|
|
const proto = request.nextUrl.protocol.replace(":", "");
|
|
|
|
|
requestHeaders.set(
|
|
|
|
|
"Forwarded",
|
|
|
|
|
`host=${request.nextUrl.host};proto=${proto}`
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-27 09:17:00 +02:00
|
|
|
requestHeaders.set("Access-Control-Allow-Origin", "*");
|
2023-09-27 09:21:51 +02:00
|
|
|
requestHeaders.set("Access-Control-Allow-Headers", "*");
|
2023-09-27 09:17:00 +02:00
|
|
|
|
2023-09-27 09:01:25 +02:00
|
|
|
console.log(
|
|
|
|
|
"intercept",
|
|
|
|
|
request.nextUrl.basePath,
|
|
|
|
|
request.nextUrl.host,
|
|
|
|
|
proto
|
|
|
|
|
);
|
2023-08-18 10:46:13 +02:00
|
|
|
|
|
|
|
|
request.nextUrl.href = `${INSTANCE}${request.nextUrl.pathname}${request.nextUrl.search}`;
|
|
|
|
|
return NextResponse.rewrite(request.nextUrl, {
|
|
|
|
|
request: {
|
|
|
|
|
headers: requestHeaders,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|