mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 09:31:13 -05:00
Fix: Address HMR failures and Fast Refresh incompatibility
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user