import { NextResponse } from "next/server" import type { NextRequest } from "next/server" const CHILD_HOST = "mate" const PARENT_HOST = "simulacro" export function middleware(request: NextRequest) { const hostname = request.headers.get("host") || "" const { pathname } = request.nextUrl if (pathname.startsWith("/api") || pathname.startsWith("/_next") || pathname.startsWith("/static") || pathname === "/favicon.ico") { return NextResponse.next() } if (hostname.includes(CHILD_HOST)) { if (pathname === "/" || pathname.startsWith("/child")) { return NextResponse.next() } const url = request.nextUrl.clone() url.pathname = `/child${pathname === "/" ? "" : pathname}` return NextResponse.rewrite(url) } if (hostname.includes(PARENT_HOST)) { if (pathname === "/" || pathname.startsWith("/parent")) { return NextResponse.next() } const url = request.nextUrl.clone() url.pathname = `/parent${pathname === "/" ? "" : pathname}` return NextResponse.rewrite(url) } return NextResponse.next() } export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"], }