refactor(middleware): improve readability by modularizing logic and adding documentation
- Broke down the middleware into smaller, more descriptive functions.
- Added documentation to each function, explaining its purpose and usage.
- Streamlined the code to enhance its readability, making the template more accessible to developers of varying skill levels.
@joelybahh is attempting to deploy a commit to the Vercel Labs Team on Vercel.
A member of the Team first needs to authorize it.
you are awesome
@joelybahh you are incredible! this refactor was so helpful to me.
could you help again?
I have launched this multi-tenant app successfully on vercel and I have several custom domains. It works locally great as well. My only issue is I cannot currently get it to work with production for cell generated domains or vercel generated preview domains.
i believe the problem is going to be occurring here in the code:
/**
* Processes the request hostname, adjusting it for local development and Vercel preview deployments.
* It ensures that the hostname is standardized to use the application's root domain environment variable.
*
* @param {NextRequest} req - The incoming request object.
* @returns {string} The processed hostname.
*/
function getProcessedHostname(req: NextRequest) {
let hostname = req.headers.get("host")!.replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`);
if (hostname.includes("---") && hostname.endsWith(`.${process.env.NEXT_PUBLIC_VERCEL_DEPLOYMENT_SUFFIX}`)) {
hostname = `${hostname.split("---")[0]}.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`;
}
return hostname;
}
i believe the problem is going to be occurring here in the code:
/** * Processes the request hostname, adjusting it for local development and Vercel preview deployments. * It ensures that the hostname is standardized to use the application's root domain environment variable. * * @param {NextRequest} req - The incoming request object. * @returns {string} The processed hostname. */ function getProcessedHostname(req: NextRequest) { let hostname = req.headers.get("host")!.replace(".localhost:3000", `.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`); if (hostname.includes("---") && hostname.endsWith(`.${process.env.NEXT_PUBLIC_VERCEL_DEPLOYMENT_SUFFIX}`)) { hostname = `${hostname.split("---")[0]}.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}`; } return hostname; }
I am actually wondering if vercel changed their construction of deployment suffixes... i have also upgraded to a paid account and wonder if maybe paid accounts have a different construction for deployment suffixes and hostname construction.