vector / frontend /middleware.ts
d-ragon's picture
Upload 674 files
689359a verified
Raw History Blame Contribute Delete
1.11 kB
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const PUBLIC_FILE = /\.(.*)$/;
export function middleware(request: NextRequest) {
const isLandingOnlyModeEnabled =
process.env.NEXT_PUBLIC_LANDING_ONLY_MODE === "true";
if (!isLandingOnlyModeEnabled) {
return NextResponse.next();
}
const { pathname } = request.nextUrl;
if (
pathname === "/" ||
pathname === "/status" ||
pathname.startsWith("/_next") ||
pathname.startsWith("/api/billing/webhook") ||
pathname.startsWith("/ingest/") ||
// Opt-outs (including mailbox one-click POSTs) must work in every mode.
pathname === "/email/product-updates/unsubscribe" ||
PUBLIC_FILE.test(pathname)
) {
return NextResponse.next();
}
if (pathname.startsWith("/api")) {
return NextResponse.json(
{ error: "SupoClip is in landing-page-only mode." },
{ status: 503 }
);
}
const url = request.nextUrl.clone();
url.pathname = "/";
url.search = "";
return NextResponse.redirect(url);
}
export const config = {
matcher: "/:path*",
};