mirror of
https://github.com/stackblitz/bolt.new
synced 2024-11-27 22:42:21 +00:00
20 lines
686 B
TypeScript
20 lines
686 B
TypeScript
import { json, type ActionFunctionArgs } from '@remix-run/cloudflare';
|
|
import { actionWithAuth } from '~/lib/.server/auth';
|
|
import type { Session } from '~/lib/.server/sessions';
|
|
import { sendEventInternal, type AnalyticsEvent } from '~/lib/analytics';
|
|
|
|
async function analyticsAction({ request }: ActionFunctionArgs, session: Session) {
|
|
const event: AnalyticsEvent = await request.json();
|
|
const { success, error } = await sendEventInternal(session, event);
|
|
|
|
if (!success) {
|
|
return json({ error }, { status: 500 });
|
|
}
|
|
|
|
return json({ success }, { status: 200 });
|
|
}
|
|
|
|
export async function action(args: ActionFunctionArgs) {
|
|
return actionWithAuth(args, analyticsAction);
|
|
}
|