INNER CODE UNIT · TypeScript
maybeRedirectToCanonicalHost
Ammaar-Alam/minebench · middleware.ts:86
function maybeRedirectToCanonicalHost(req: NextRequest) {
if (process.env.NODE_ENV !== "production") return null;
const hostHeader = req.headers.get("host");
if (!hostHeader) return null;
const host = hostHeader.split(":")[0]?.toLowerCase();
if (!host || !LEGACY_HOSTS.has(host)) return null;
const nextUrl = req.nextUrl.clone();
nextUrl.protocol = "https";
nextUrl.host = SITE_HOST;
return NextResponse.redirect(nextUrl, 308);
}
function safeDecodeURIComponent(value: string): string | null {
try {
return decodeURIComponent(value);
} catch {