🔨 fix cors issue (2)

This commit is contained in:
platane
2024-07-06 11:47:56 +02:00
parent d35dc83cf2
commit 876448a004

View File

@@ -11,9 +11,10 @@ export default async (req: VercelRequest, res: VercelResponse) => {
"https://platane.github.io", "https://platane.github.io",
"https://platane.me", "https://platane.me",
]; ];
const reqOrigin =
req.url && new URL(req.url, `http://${req.headers.host}`)?.origin; const allowedOrigin = allowedOrigins.find(
const allowedOrigin = allowedOrigins.find((o) => o === reqOrigin); (o) => o === req.headers.origin
);
if (allowedOrigin) if (allowedOrigin)
res.setHeader("Access-Control-Allow-Origin", allowedOrigin); res.setHeader("Access-Control-Allow-Origin", allowedOrigin);
} }