import { NextResponse, type NextRequest } from "next/server";
import { authMiddleware } from "~/middlewares/auth_middleware";

export async function middleware(request: NextRequest) {
  //console.log("Middleware triggered for:", request.nextUrl.pathname);

  return (await authMiddleware(request)) ?? NextResponse.next();
}

export const config = {
  matcher: [
    {
      source: "/",
    },
    {
      source:
        "/((?!api/trpc|go-api/images|api/tiles|api/auth|_next/static|_next/image|screenshots|site.webmanifest|favicon.ico|favicon|sitemap.xml|robots.txt).*)",
      missing: [
        { type: "header", key: "next-router-prefetch" },
        { type: "header", key: "purpose", value: "prefetch" },
      ],
    },
  ],
};
