Server is done

This commit is contained in:
2024-10-17 15:47:39 -05:00
parent f734551d3a
commit 69a6bb656e
11 changed files with 370 additions and 13 deletions

22
src/middleware.ts Normal file
View File

@@ -0,0 +1,22 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export async function middleware(request: NextRequest): Promise<NextResponse | undefined> {
try {
const apiKey = request.headers.get('x-api-key');
if (!apiKey || apiKey !== process.env.API_KEY) {
return NextResponse.json({ message: 'Invalid API key' }, { status: 401 });
}
// If the API key is valid, we don't return anything, allowing the request to proceed
return undefined;
} catch (error) {
console.error('Middleware error:', error);
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
}
}
export const config = {
matcher: '/api/:path*',
};