Spaces:
Sleeping
Sleeping
| import { NextRequest, NextResponse } from 'next/server'; | |
| export function middleware(request: NextRequest) { | |
| if (request.method === 'OPTIONS') { | |
| const origin = request.headers.get('origin') || '*'; | |
| return new NextResponse(null, { | |
| status: 204, | |
| headers: { | |
| 'Access-Control-Allow-Origin': origin, | |
| 'Access-Control-Allow-Credentials': 'true', | |
| 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', | |
| 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Bot-Api-Key, X-Internal-Call', | |
| 'Access-Control-Max-Age': '86400', | |
| }, | |
| }); | |
| } | |
| const origin = request.headers.get('origin'); | |
| const response = NextResponse.next(); | |
| if (origin) { | |
| response.headers.set('Access-Control-Allow-Origin', origin); | |
| response.headers.set('Access-Control-Allow-Credentials', 'true'); | |
| response.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS'); | |
| response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Bot-Api-Key, X-Internal-Call'); | |
| } | |
| return response; | |
| } | |
| export const config = { | |
| matcher: '/api/:path*', | |
| }; | |