databuddy-analytics / databuddy-analytics/Databuddy
API returning 500 server error
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 216
- Avg merge
- 14h 53m
- Merged PRs (30d)
- 154
Description
export const prerender = false;
export async function GET() {
const apiKey = import.meta.env.DATABUDDY_API_KEY;
const websiteId = import.meta.env.DATABUDDY_WEBSITE_ID;
if (!apiKey || !websiteId) {
return new Response(
JSON.stringify({ error: "Missing API credentials" }),
{ status: 500, headers: { "Content-Type": "application/json" } }
);
}
try {
const response = await fetch(`https://api.databuddy.cc/v1/websites/${websiteId}/stats?period=30d`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error('Failed to fetch stats from Databuddy');
}
const data = await response.json();
return new Response(
JSON.stringify({ pageviews: data.pageviews || 0 }),
{
status: 200,
headers: {
"Content-Type": "application/json",
"Cache-Control": "public, max-age=86400, stale-while-revalidate=43200",
},
}
);
} catch (error) {
const message = error instanceof Error ? error.message : "An unexpected error occurred";
return new Response(
JSON.stringify({ error: message }),
{ status: 500, headers: { "Content-Type": "application/json" } }
);
}
}
this is my API fetch and its returning a 500 server error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the API route containing the GET handler shown in the issue and run it with the relevant environment variables configured. Check the server response and the Databuddy stats request to identify which step produces the 500 error. Done means the endpoint no longer returns an unexpected 500 for a valid configuration and its error behavior is covered or documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100