import { type NextRequest, NextResponse } from "next/server"; import { livestreamEnabled } from "@/lib/toolsEnabled"; import { isPostSchedulingEnabled } from "@/lib/postScheduling"; import { brandAccountsEnabled } from "@/lib/brandAccountsEnabled"; /** Cover direct requests, nested routes, and client navigation to Tools. */ export function proxy(request: NextRequest) { const section = request.nextUrl.pathname.split("/")[1]; // Articles and Analytics have their own authenticated layouts. if (section === "articles" || section === "analytics") return NextResponse.next(); const scheduling = section === "content-calendar" || section === "scheduling"; if (section === "media" || (section === "livestream" && !livestreamEnabled()) || (section === "brand-accounts" && !brandAccountsEnabled()) || (scheduling && !isPostSchedulingEnabled())) { return new NextResponse("Not Found", { status: 404, headers: { "Cache-Control": "private, no-store" }, }); } return NextResponse.next(); } export const config = { matcher: [ "/articles/:path*", "/live-post/:path*", "/media/:path*", "/livestream/:path*", "/brand-accounts/:path*", "/content-calendar/:path*", "/analytics/:path*", "/scheduling/:path*", ], };