🐛 rewrite url from headers (#1369)

This commit is contained in:
Tagaishi
2023-09-07 21:35:55 +02:00
committed by GitHub
parent 89cfb1ae5d
commit 3ede6219ef

View File

@@ -26,7 +26,14 @@ export function middleware(req: NextRequest) {
// If the password is not correct, redirect to the login page
if (!isCorrectPassword && process.env.PASSWORD) {
url.pathname = '/login';
return NextResponse.rewrite(url);
/*//--- nextjs doesn't use X-Forwarded yet, if we need to update the dependency, add this code
url.host = req.headers.get('X-Forwarded-Host')?? url.host;
url.port = req.headers.get('X-Forwarded-Port')?? url.port;
url.protocol = req.headers.get('X-Forwarded-Proto')?? url.protocol;
//---*/
return NextResponse.redirect(url);
}
return NextResponse.next();
}