import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; /** * Root "/" → staging preview wrapper, host-gated. * * The current landing is rendered directly by app/page.tsx in production. * Local development and staging are rewritten through /playground so the same * screen keeps its noindex preview metadata there. The visual content is shared * between both routes; only the environment-specific metadata and login target * differ. * * Matcher is "/" only, so no other route pays any middleware cost. */ export function middleware(req: NextRequest) { const host = ( req.headers.get("x-forwarded-host") || req.headers.get("host") || "" ).toLowerCase(); const showPlayground = process.env.NODE_ENV !== "production" || // local dev process.env.SHOW_PLAYGROUND === "1" || // manual override host.startsWith("staging.") || // staging.hivegrid.de → on host.includes("localhost") || host.startsWith("127.0.0.1"); if (showPlayground) { const url = req.nextUrl.clone(); url.pathname = "/playground"; return NextResponse.rewrite(url); } return NextResponse.next(); } export const config = { matcher: "/", };