mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 19:31:14 -05:00
feat: Implement comprehensive request tracking and state management
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { serve } from "https://deno.land/std@0.168.0/http/server.ts";
|
||||
import { Novu } from "npm:@novu/api@1.6.0";
|
||||
|
||||
// TODO: In production, restrict CORS to specific domains
|
||||
// For now, allowing all origins for development flexibility
|
||||
// Example production config: 'Access-Control-Allow-Origin': 'https://yourdomain.com'
|
||||
const corsHeaders = {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'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;
|
||||
|
||||
serve(async (req) => {
|
||||
const tracking = startRequest();
|
||||
|
||||
if (req.method === 'OPTIONS') {
|
||||
return new Response(null, { headers: corsHeaders });
|
||||
}
|
||||
@@ -197,28 +200,32 @@ serve(async (req) => {
|
||||
data,
|
||||
});
|
||||
|
||||
console.log('Subscriber created successfully:', subscriber.data);
|
||||
const duration = endRequest(tracking);
|
||||
console.log('Subscriber created successfully:', subscriber.data, { requestId: tracking.requestId, duration });
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
subscriberId: subscriber.data._id,
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json', 'X-Request-ID': tracking.requestId },
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error creating Novu subscriber:', error);
|
||||
const duration = endRequest(tracking);
|
||||
console.error('Error creating Novu subscriber:', error, { requestId: tracking.requestId, duration });
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
requestId: tracking.requestId
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json', 'X-Request-ID': tracking.requestId },
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user