Skip to content

Commit

Permalink
Merge pull request #47 from pumbas600/fix/cors-blocking-requests
Browse files Browse the repository at this point in the history
Fix/cors blocking requests
  • Loading branch information
pumbas600 authored Oct 28, 2023
2 parents 106b356 + 3b86e21 commit 75a2d95
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest, NextResponse } from 'next/server';

export function middleware(req: NextRequest): Response {
const res = req.method === 'OPTIONS' ? new Response(undefined, { status: 204 }) : NextResponse.next();

res.headers.append('Access-Control-Allow-Origin', '*');
res.headers.append('Access-Control-Allow-Methods', 'GET');
return res;
}

export const config = {
matcher: '/api/:path*', // Match all API routes
};

1 comment on commit 75a2d95

@vercel
Copy link

@vercel vercel bot commented on 75a2d95 Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.