1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
export default async function(req: Request): Promise<Response> {
const url =
"https://script.google.com/macros/s/AKfycbwzkp9Nr29pws2ShKq9ZlI1W-DaLmKBJbGBk8kYuw4bOkmyWvgdE7E6M5d6YwUITekf/exec";
try {
// Fetch the data from the Google Script URL
const response = await fetch(url);
const jsonData = await response.json();
// Extract the email parameter from the query string
const email = new URL(req.url).searchParams.get("email");
if (!email) {
// If no email parameter is provided, return the entire data
return new Response(JSON.stringify(jsonData), {
headers: { "Content-Type": "application/json" },
});
}
// Find the object in the data array that matches the provided email
const record = jsonData.data.find((item: { email: string }) => item.email === email);
if (!record) {
return new Response("No record found for the provided email", { status: 404 });
}
// Return the date associated with the email
return new Response(JSON.stringify({ date: record.date }), {
headers: { "Content-Type": "application/json" },
});
} catch (error) {
return new Response("Failed to fetch data", { status: 500 });
}
}