Skip to content

Commit

Permalink
🔨 fix cors issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Platane committed Jul 6, 2024
1 parent bb7d69d commit d35dc83
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ export default async (req: VercelRequest, res: VercelResponse) => {
const { userName } = req.query;

try {
res.setHeader("Access-Control-Allow-Origin", "https://platane.github.io");
// handle CORS
{
const allowedOrigins = [
"https://platane.github.io",
"https://platane.me",
];
const reqOrigin =
req.url && new URL(req.url, `http://${req.headers.host}`)?.origin;
const allowedOrigin = allowedOrigins.find((o) => o === reqOrigin);
if (allowedOrigin)
res.setHeader("Access-Control-Allow-Origin", allowedOrigin);
}
res.setHeader("Cache-Control", "max-age=21600, s-maxage=21600");
res.statusCode = 200;
res.json(
Expand Down

0 comments on commit d35dc83

Please sign in to comment.