fix vercel load errors

This commit is contained in:
Christian Vidal Wolf
2026-05-20 13:57:11 +02:00
parent 88dc894050
commit e8d05069f3
8 changed files with 75 additions and 91 deletions
+8 -9
View File
@@ -1,7 +1,8 @@
import { applyCors, isAllowedOrigin } from './_cors.js';
const SUPABASE_URL = process.env.SUPABASE_URL || 'https://hwithddwaapyhnfwcesj.supabase.co';
const SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY;
const SUPABASE_ANON_KEY = 'sb_publishable_fGXkh0bSrAOqSk2jWKAzSg_NJD9YPCv';
const ALLOWED_ORIGIN = 'https://craze-data-check.vercel.app';
const MASTER_USERS = new Set([
'christian.vidal@craze-group.com',
@@ -9,14 +10,7 @@ const MASTER_USERS = new Set([
]);
function setCors(req, res) {
const origin = req.headers.origin;
if (origin === ALLOWED_ORIGIN || (origin && (origin.startsWith('http://localhost:') || origin.startsWith('http://127.0.0.1:')))) {
res.setHeader('Access-Control-Allow-Origin', origin);
}
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization, apikey');
res.setHeader('Access-Control-Max-Age', '86400');
res.setHeader('Vary', 'Origin');
applyCors(req, res, 'POST, OPTIONS');
}
export default async function handler(req, res) {
@@ -26,6 +20,11 @@ export default async function handler(req, res) {
return res.status(204).end();
}
const origin = req.headers.origin;
if (origin && !isAllowedOrigin(origin)) {
return res.status(403).json({ error: 'Forbidden' });
}
try {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed' });