NORY-26: add protocol to middleware redirects

This commit is contained in:
Markus Thielker 2024-12-26 12:31:41 +01:00
parent b6ce48e03e
commit fe1c5cc83a
No known key found for this signature in database

View file

@ -12,14 +12,13 @@ export async function middleware(request: NextRequest) {
.then((response) => response.data)
.catch(() => null);
const nodeHost = request.nextUrl.protocol + '//' + request.nextUrl.host;
if (!session && !request.nextUrl.pathname.startsWith('/flow')) {
console.log('NO SESSION');
const url = request.nextUrl.host +
'/flow/login?return_to=' +
request.nextUrl.host +
request.nextUrl.pathname;
const url = nodeHost + '/flow/login?return_to=' + request.nextUrl.toString();
console.log('REDIRECT TO', url);
@ -30,7 +29,7 @@ export async function middleware(request: NextRequest) {
console.log('SESSION EXISTS');
const returnTo = request.nextUrl.searchParams.get('return_to') ?? request.nextUrl.host;
const returnTo = request.nextUrl.searchParams.get('return_to') ?? nodeHost;
console.log('REDIRECT TO', returnTo);
@ -41,5 +40,5 @@ export async function middleware(request: NextRequest) {
}
export const config = {
matcher: '/((?!api|_next/static|_next/image|favicon.png|sitemap.xml|robots.txt|sw.js).*)',
matcher: '/((?!api|_next/static|_next/image|favicon.png|sitemap.xml|robots.txt|sw.js|manifest.json|icon-72.png|icon-128.png|icon-144.png|icon-192.png|icon-512.png|mt-logo-orange.png).*)',
};