feat(web): edge middleware deny /api except events + health
This commit is contained in:
parent
1fe674c70e
commit
8771e65c8c
17
apps/web/src/middleware.ts
Normal file
17
apps/web/src/middleware.ts
Normal 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-).*)"],
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user