// middleware.ts import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; const LAUNCH_ONLY_ROOT = process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT === "true"; // Allow only root + essential static files const ALLOW = new Set([ "/", "/favicon.ico", "/robots.txt", "/sitemap.xml", ]); export function middleware(req: NextRequest) { if (!LAUNCH_ONLY_ROOT) return NextResponse.next(); const { pathname } = req.nextUrl; // Always allow Next internals + static assets if ( pathname.startsWith("/_next") || pathname.startsWith("/assets") || pathname.startsWith("/images") ) { return NextResponse.next(); } // Allow the root + a few public files if (ALLOW.has(pathname)) return NextResponse.next(); // Everything else: hide it return NextResponse.rewrite(new URL("/404", req.url)); // or redirect to "/" } export const config = { matcher: ["/:path*"], };