MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / fetch

Function fetch

backend/feedback-api/src/index.ts:11–108  ·  view source on GitHub ↗
(request, env, ctx)

Source from the content-addressed store, hash-verified

9
10export default {
11 async fetch(request, env, ctx) {
12 // Get the request URL and path
13 const url = new URL(request.url);
14 const path = url.pathname;
15
16 // Only process requests to /api/feedback
17 if (path !== '/api/feedback') {
18 return new Response('Not found', {
19 status: 404,
20 headers: corsHeaders
21 });
22 }
23
24 // Handle CORS preflight requests
25 if (request.method === 'OPTIONS') {
26 return new Response(null, {
27 headers: corsHeaders,
28 });
29 }
30
31 // Only allow POST for actual requests
32 if (request.method !== 'POST') {
33 return new Response('Method not allowed', {
34 status: 405,
35 headers: corsHeaders,
36 });
37 }
38
39 try {
40 // Parse request body as JSON
41 const body = await request.json();
42 const { message, email, context } = body;
43
44 // Validate input
45 if (!message || typeof message !== 'string') {
46 return new Response(JSON.stringify({ error: 'Message is required' }), {
47 status: 400,
48 headers: {
49 'Content-Type': 'application/json',
50 ...corsHeaders,
51 },
52 });
53 }
54
55 // Initialize Resend with API key from environment
56 const resend = new Resend(env.RESEND_API_KEY);
57
58 // Get user info
59 const userEmail = email && typeof email === 'string' ? email : 'Anonymous user';
60 const contextInfo = context || 'No context provided';
61 const timestamp = new Date().toISOString();
62
63 // Send email
64 const { data, error } = await resend.emails.send({
65 from: 'DataKit Feedback <feedback@datakit.page>',
66 to: ['amin@datakit.page', 'luke@datakit.page'],
67 subject: 'New DataKit Feedback',
68 html: `

Callers 15

onRequestFunction · 0.85
handleSubmitFunction · 0.85
useGoogleDriveImportFunction · 0.85
makeLocalProxyRequestMethod · 0.85
checkLocalProxyMethod · 0.85
checkCORSAnywhereMethod · 0.85
validateConnectionMethod · 0.85
listModelsMethod · 0.85
generateCompletionMethod · 0.85
pullModelMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected