Skip to content

Commit

Permalink
chore: add cors disabled middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalavedra committed Aug 7, 2024
1 parent 2e6867b commit ca584a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 0 additions & 21 deletions examples/apps/auth-sample/next.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
/** @type {import('next').NextConfig} */
module.exports = {
reactStrictMode: true,
async headers() {
return [
{
// matching all API routes
source: '/api/:path*',
headers: [
{key: 'Access-Control-Allow-Credentials', value: 'true'},
{key: 'Access-Control-Allow-Origin', value: '*'},
{
key: 'Access-Control-Allow-Methods',
value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT',
},
{
key: 'Access-Control-Allow-Headers',
value:
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization',
},
],
},
];
},
};
21 changes: 21 additions & 0 deletions examples/apps/auth-sample/src/pages/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export function middleware(req: NextRequest) {
const res = NextResponse.next();

res.headers.set('Access-Control-Allow-Credentials', 'true');
res.headers.set('Access-Control-Allow-Origin', '*');
res.headers.set('Access-Control-Allow-Methods', 'GET,OPTIONS,PATCH,DELETE,POST,PUT');
res.headers.set('Access-Control-Allow-Headers', 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Authorization');

if (req.method === 'OPTIONS') {
return new NextResponse(null, { status: 200, headers: res.headers });
}

return res;
}

export const config = {
matcher: '/api/:path*',
}

0 comments on commit ca584a0

Please sign in to comment.