Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions apps/web/src/routes/devcard/analytics/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { PageServerLoad } from './$types';

const API_BASE = process.env.BACKEND_URL || 'http://localhost:3000';

export const load: PageServerLoad = async ({ fetch }) => {
try {
const [overviewRes, viewsRes] = await Promise.all([
fetch(`${API_BASE}/api/analytics/overview`),
fetch(`${API_BASE}/api/analytics/views`)
]);

if (!overviewRes.ok || !viewsRes.ok) {
// If unauthorized, we might return mock data for demonstration purposes
// in this dev phase, but officially we should return error.
// Let's return error to follow "nothing that can break in production"
return {
overview: null,
views: null,
error: 'Please log in to view analytics'
};
}

const overview = await overviewRes.json();
const views = await viewsRes.json();

return { overview, views, error: null };
} catch (err) {
return {
overview: null,
views: null,
error: 'Analytics service unavailable'
};
}
};
Loading
Loading