allow options as well

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-11-04 20:26:35 +01:00
parent 853e6adbe2
commit 3431958c79
8 changed files with 44 additions and 20 deletions

View File

@@ -0,0 +1,24 @@
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
export const config = { matcher: ['/api/sdk/:path*'] };
export const cors = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, PUT, OPTIONS',
'Access-Control-Allow-Headers':
'Content-Type, Authorization, Mixan-Client-Id, Mixan-Client-Secret',
};
export function middleware(request: NextRequest) {
const response = NextResponse.next();
if (request.method === 'OPTIONS') {
return NextResponse.json({}, { headers: cors });
}
Object.entries(cors).forEach(([key, value]) => {
response.headers.append(key, value);
});
return response;
}