import { NextRequest, NextResponse } from "next/server"; const PUBLIC_UTILITY_APIS = new Set([ "/api/bgbye/process", "/api/files/list", "/api/files/raw", "/api/files/download", ]); const LEGACY_TOOL_PATHS: Record = { "/laser-toolkit": "laser-toolkit", "/files": "files", "/background-remover": "background-remover", }; /** * Temporary utility-only site. * * Directus-backed pages and APIs remain in source history but cannot be reached * through this deployment. This middleware deliberately performs no session or * Directus request. */ export function middleware(req: NextRequest) { const { pathname } = req.nextUrl; if (pathname === "/") return NextResponse.next(); const legacyTool = LEGACY_TOOL_PATHS[pathname.replace(/\/$/, "")]; if (legacyTool) { const url = req.nextUrl.clone(); url.pathname = "/"; url.search = ""; url.searchParams.set("tool", legacyTool); return NextResponse.redirect(url); } if (pathname === "/portal/utilities") { const url = req.nextUrl.clone(); const requested = url.searchParams.get("t"); url.pathname = "/"; url.search = ""; if (requested && ["laser-toolkit", "files", "background-remover"].includes(requested)) { url.searchParams.set("tool", requested); } return NextResponse.redirect(url); } if (PUBLIC_UTILITY_APIS.has(pathname)) return NextResponse.next(); if (pathname.startsWith("/api/")) { return NextResponse.json({ error: "Not available on the temporary utility site" }, { status: 404 }); } const home = req.nextUrl.clone(); home.pathname = "/"; home.search = ""; return NextResponse.redirect(home); } export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|images|static).*)"], };