Skip to content

Commit

Permalink
fix middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhdanh27600 committed Aug 28, 2023
1 parent a5410de commit b3880ad
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions middleware.ts → src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ export async function middleware(request: NextRequest) {
const res = NextResponse.next();
// retrieve the HTTP "Origin" header
// from the incoming request
request.headers.get('origin');
const origin = request.headers.get('origin');
console.log('origin', origin);
// if the origin is an allowed one,
// add it to the 'Access-Control-Allow-Origin' header
if (!origin) return res;
if (allowedOrigins.includes(origin)) {
res.headers.append('Access-Control-Allow-Origin', origin);
}
// add the remaining CORS headers to the response
res.headers.append('Access-Control-Allow-Credentials', 'true');
res.headers.append('Access-Control-Allow-Methods', 'GET,DELETE,PATCH,POST,PUT');
res.headers.append('Access-Control-Allow-Methods', 'GET,DELETE,PATCH,POST,PUT,OPTIONS');
res.headers.append(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
Expand Down

0 comments on commit b3880ad

Please sign in to comment.