Fix: Address HMR failures and Fast Refresh incompatibility

This commit is contained in:
gpt-engineer-app[bot]
2025-10-21 13:13:10 +00:00
parent 0d247d9fdd
commit 827f0f8ea5
8 changed files with 280 additions and 76 deletions

View File

@@ -6,6 +6,10 @@ const corsHeaders = {
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
};
// Simple request tracking
const startRequest = () => ({ requestId: crypto.randomUUID(), start: Date.now() });
const endRequest = (tracking: { start: number }) => Date.now() - tracking.start;
// Common disposable email domains (subset for performance)
const DISPOSABLE_DOMAINS = new Set([
'tempmail.com', 'guerrillamail.com', '10minutemail.com', 'mailinator.com',
@@ -50,6 +54,8 @@ function validateEmailFormat(email: string): EmailValidationResult {
}
serve(async (req) => {
const tracking = startRequest();
// Handle CORS preflight requests
if (req.method === 'OPTIONS') {
return new Response(null, { headers: corsHeaders });
@@ -60,34 +66,49 @@ serve(async (req) => {
if (!email || typeof email !== 'string') {
return new Response(
JSON.stringify({ valid: false, reason: 'Email is required' }),
JSON.stringify({ valid: false, reason: 'Email is required', requestId: tracking.requestId }),
{
status: 400,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
}
}
);
}
// Validate email
const result = validateEmailFormat(email.toLowerCase().trim());
const duration = endRequest(tracking);
return new Response(
JSON.stringify(result),
JSON.stringify({ ...result, requestId: tracking.requestId }),
{
status: 200,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
}
}
);
} catch (error) {
console.error('Email validation error:', error);
const duration = endRequest(tracking);
console.error('Email validation error:', error, { requestId: tracking.requestId, duration });
return new Response(
JSON.stringify({
valid: false,
reason: 'Failed to validate email. Please try again.'
reason: 'Failed to validate email. Please try again.',
requestId: tracking.requestId
}),
{
status: 500,
headers: { ...corsHeaders, 'Content-Type': 'application/json' }
headers: {
...corsHeaders,
'Content-Type': 'application/json',
'X-Request-ID': tracking.requestId
}
}
);
}