Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does redirect preserve the subdomain when printing req.url doesn't show the subdomain #423

Open
RahulBirCodes opened this issue Jul 27, 2024 · 0 comments

Comments

@RahulBirCodes
Copy link

RahulBirCodes commented Jul 27, 2024

In the middleware at this part where it matches requests accessing the app subdomain:

if (hostname == `app.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`) {
    const session = await getToken({ req });
    if (!session && path !== "/login") {
      return NextResponse.redirect(new URL("/login", req.url));
    } else if (session && path == "/login") {
      return NextResponse.redirect(new URL("/", req.url));
    }
    return NextResponse.rewrite(
      new URL(`/app${path === "/" ? "" : path}`, req.url),
    );
  }

when I print out the value of req.url it only gives me http://localhost:3000, however it correctly redirects to app.localhost:3000/login. So the req.url is clearly preserving the value somehow of the domain but doesn't show that when it prints. However, in the rewrite where we add /app to the path we also use req.url but if req.url is preserving the subdomain won't this lead to issues when it reaches the server? Not sure if I'm missing something but any clarity on this is appreciated!

@RahulBirCodes RahulBirCodes changed the title How does redirect preserve the subdomain when printing doesn't show the subdomain How does redirect preserve the subdomain when printing req.url doesn't show the subdomain Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant