fix: rename middleware.ts to proxy.ts (deprecated convention)
This commit is contained in:
parent
25c959fd18
commit
522c2f269d
2 changed files with 1 additions and 1 deletions
33
src/proxy.ts
Normal file
33
src/proxy.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// Skip auth check for the health endpoint
|
||||
if (pathname === "/api/health") {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
const apiKey = process.env.API_KEY;
|
||||
|
||||
// If API_KEY is not configured, skip auth check (fail-open for development)
|
||||
if (!apiKey) {
|
||||
console.warn(
|
||||
"Warning: API_KEY environment variable is not set. API authentication is disabled."
|
||||
);
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
const requestApiKey = request.headers.get("X-API-Key");
|
||||
|
||||
if (!requestApiKey || requestApiKey !== apiKey) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/api/:path*"],
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue