-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
16 lines (13 loc) · 567 Bytes
/
Copy pathproxy.ts
File metadata and controls
16 lines (13 loc) · 567 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
const SAFE_METHODS = new Set(["GET", "HEAD", "OPTIONS"]);
export function proxy(request: NextRequest) {
if (!SAFE_METHODS.has(request.method) && request.headers.get("sec-fetch-site") === "cross-site") {
return NextResponse.json(
{ error: { code: "CROSS_SITE_REQUEST_REJECTED", message: "Cross-site state-changing requests are not allowed." } },
{ status: 403 }
);
}
return NextResponse.next();
}
export const config = { matcher: "/api/:path*" };