-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
31 lines (25 loc) · 814 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
31 lines (25 loc) · 814 Bytes
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
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
// Only apply to /api/usage routes
if (!request.nextUrl.pathname.startsWith("/api/usage")) {
return NextResponse.next();
}
// Allow GET requests with credentials
if (request.method === "GET") {
const username = request.nextUrl.searchParams.get("username");
const password = request.nextUrl.searchParams.get("password");
if (!username || !password) {
return NextResponse.json(
{ error: "Missing credentials" },
{ status: 400 }
);
}
return NextResponse.next();
}
// Block all other methods
return new NextResponse(null, { status: 405 });
}
export const config = {
matcher: "/api/usage/:path*",
};