infoalloggi-monorepo/apps/infoalloggi/src/middleware.ts

31 lines
911 B
TypeScript
Raw Normal View History

2025-08-28 18:27:07 +02:00
import { type NextRequest, NextResponse } from "next/server";
2025-08-04 17:45:44 +02:00
import { authMiddleware } from "~/middlewares/auth_middleware";
import { apisMiddleware } from "./middlewares/api_middleware";
2025-08-04 17:45:44 +02:00
export async function middleware(request: NextRequest) {
2025-08-28 18:27:07 +02:00
//console.log("Middleware triggered for:", request.nextUrl.pathname);
const { pathname } = request.nextUrl;
if (pathname.startsWith("/storage-api/")) {
return await apisMiddleware(request);
}
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
return (await authMiddleware(request)) ?? NextResponse.next();
2025-08-04 17:45:44 +02:00
}
export const config = {
2025-08-28 18:27:07 +02:00
matcher: [
"/storage-api/:path*",
2025-08-28 18:27:07 +02:00
{
source: "/",
},
{
missing: [
2025-08-29 16:18:32 +02:00
{ key: "next-router-prefetch", type: "header" },
{ key: "purpose", type: "header", value: "prefetch" },
2025-08-28 18:27:07 +02:00
],
2025-08-29 16:18:32 +02:00
source:
"/((?!api/trpc|storage-api|api/tiles|api/auth|_next/static|_next/image|screenshots|site.webmanifest|favicon.ico|favicon|sitemap.xml|robots.txt).*)",
2025-08-28 18:27:07 +02:00
},
],
2025-08-04 17:45:44 +02:00
};