bolt.new/packages/bolt/app/routes/api.analytics.ts

20 lines
686 B
TypeScript
Raw Normal View History

2024-08-12 15:37:45 +00:00
import { json, type ActionFunctionArgs } from '@remix-run/cloudflare';
2024-08-22 08:11:38 +00:00
import { actionWithAuth } from '~/lib/.server/auth';
import type { Session } from '~/lib/.server/sessions';
2024-08-12 15:37:45 +00:00
import { sendEventInternal, type AnalyticsEvent } from '~/lib/analytics';
2024-08-22 08:11:38 +00:00
async function analyticsAction({ request }: ActionFunctionArgs, session: Session) {
2024-08-12 15:37:45 +00:00
const event: AnalyticsEvent = await request.json();
2024-08-22 08:11:38 +00:00
const { success, error } = await sendEventInternal(session, event);
2024-08-12 15:37:45 +00:00
if (!success) {
return json({ error }, { status: 500 });
}
return json({ success }, { status: 200 });
}
export async function action(args: ActionFunctionArgs) {
2024-08-22 08:11:38 +00:00
return actionWithAuth(args, analyticsAction);
2024-08-12 15:37:45 +00:00
}