Skip to content

Commit

Permalink
Patch: Updated CORS Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
viveknigam3003 committed Sep 26, 2021
1 parent 8b0cc04 commit 17a73e6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions middleware/allowCors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ const allowCors =
};
}
) => {
const origin = process.env.NEXT_PUBLIC_R8
? process.env.NEXT_PUBLIC_R8.toString()
: "";

res.setHeader("Access-Control-Allow-Credentials", true);
res.setHeader("Access-Control-Allow-Origin", "*");
// another common pattern
// res.setHeader('Access-Control-Allow-Origin', req.headers.origin);
res.setHeader(
"Access-Control-Allow-Methods",
"GET,OPTIONS,PATCH,DELETE,POST,PUT"
);
res.setHeader("Access-Control-Allow-Origin", origin);
res.setHeader("Access-Control-Allow-Methods", "GET,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "*");

//To handle preflight requests
if (req.method === "OPTIONS") {
res.status(200).end();
return;
}

return await fn(req, res);
};

Expand Down

0 comments on commit 17a73e6

Please sign in to comment.