-
SummaryMy project is hosted on a VPS, running on port 2507 and I use nginx for my reverse proxy. Whatever I try to do, whenever a NextResponse.redirect is ran, it just redirects to localhost:2507 instead of the correct domain, even though I give an absolute url as a parameter. server {
server_name XXXXX.paulleflon.fr;
location / {
proxy_pass http://localhost:2507;
}
} I did try to provide some headers like Host, X-Redirect-For, etc... None of them had any effect whatsoever. And my middleware looks like this: export default async function middleware(req: NextRequest) {
const path = req.nextUrl.pathname;
const base = process.env.BASE_URL;
const isProtectedRoute = protectedRoutes.some((route) => path.startsWith(route));
// 3. Decrypt the session from the cookie
const cookie = cookies().get('session')?.value;
let session;
try {
session = cookie ? await decrypt(cookie) : null;
} catch (_) {
return NextResponse.redirect(new URL('/logout', base));
}
const isLoggedIn = typeof session?.userId === 'number';
if (path.startsWith('/login') && isLoggedIn) {
return NextResponse.redirect(new URL('/entries/daily', base));
}
// 5. Redirect to /login if the user is not authenticated
if (isProtectedRoute && !isLoggedIn) {
return NextResponse.redirect(new URL('/login', base));
}
return NextResponse.next();
} As you can see, I do provide an absolute URL. I did make sure in production that the URL was correct and the env variable was set up properly. NextJS just ignores the host and simply relatively redirects to the given route. I did try to use
I am begging you dear community, get me out of my misery. Tell me what I'm missing I'm just getting crazy. Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Please |
Beta Was this translation helpful? Give feedback.
-
Switched to SvelteKit 🚀 |
Beta Was this translation helpful? Give feedback.
Switched to SvelteKit 🚀