import { NextResponse } from "next/server"
import type { NextRequest } from "next/server"

/** 0.0.0.0 breaks cookie domain vs OIDC redirect_uri (localhost) — normalize in dev. */
export function middleware(request: NextRequest) {
  const host = request.headers.get("host") ?? ""
  if (!host.startsWith("0.0.0.0:")) {
    return NextResponse.next()
  }

  const url = request.nextUrl.clone()
  url.hostname = "localhost"
  return NextResponse.redirect(url)
}

export const config = {
  matcher: ["/((?!_next/static|_next/image|favicon.ico|.*\\..*).*)"],
}
