platforms
platforms copied to clipboard
example redirect to `${ROOT_DOMAIN}/login` to `app.${ROOT_DOMAIN}/login`
I have been trying to redirect the login page of the app for a while this is how I got it done. https://github.com/vercel/platforms/blob/7e3355678a56d9368e49cd090d729701ba4eff57/middleware.ts#L62-L69
if (
hostname === "localhost:3000" ||
hostname === process.env.NEXT_PUBLIC_ROOT_DOMAIN
) {
const https = hostname === 'localhost:3000' ? 'http' : 'https';
if (path === "/login") {
return NextResponse.redirect(new URL(`${https}://app.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/login`, req.url));
} else if (path === "/settings") {
return NextResponse.redirect(new URL(`${https}://app.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/settings`, req.url));
}
return NextResponse.rewrite(
new URL(`/home${path === "/" ? "" : path}`, req.url),
);
}
am I doing this correctly or is there a better way?
I wrote up a response recently in another issue with the same issue: https://github.com/vercel/platforms/issues/329#issuecomment-2182022845. This was the best way I found
👋 We've updated this repo to have a more simplified example + a new guide:
- https://github.com/vercel/platforms/pull/451
- https://vercel.com/guides/nextjs-multi-tenant-application