feat(web): edge middleware deny /api except events + health

This commit is contained in:
yiekheng 2026-05-09 23:15:52 +08:00
parent 1fe674c70e
commit 8771e65c8c

View File

@ -0,0 +1,17 @@
import { NextRequest, NextResponse } from "next/server";
export function middleware(req: NextRequest) {
const path = req.nextUrl.pathname;
// Block all /api/* except the read-only SSE and health endpoints.
// Mutations happen via Server Actions which post to page URLs, not /api/*.
if (path.startsWith("/api/") && path !== "/api/events" && path !== "/api/health") {
return new NextResponse("Not Found", { status: 404 });
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico|icon-).*)"],
};