File size: 1,108 Bytes
689359a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 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*",
};
|