diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 00000000..39858af3 --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1,26 @@ +import { NextResponse } from 'next/server'; +import type { NextRequest } from 'next/server'; + +export function middleware(req: NextRequest) { + const res = NextResponse.next(); + + // Set CORS headers + res.headers.set('Access-Control-Allow-Origin', '*'); + res.headers.set('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS'); + res.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization'); + + // Handle preflight OPTIONS request + if (req.method === 'OPTIONS') { + return new NextResponse(null, { + status: 204, + headers: res.headers, + }); + } + + return res; +} + +// Apply only to /api/v1/* routes +export const config = { + matcher: ['/api/v1/:path*'], +};