Files
bibdle/src/routes/+page.ts
T

26 lines
732 B
TypeScript

import type { PageLoad } from './$types';
import { getOrCreateAnonymousId } from '$lib/utils/analytics';
// Disable SSR so the load function runs on the client with the correct local date
export const ssr = false;
export const load: PageLoad = async ({ fetch, data }) => {
const localDate = new Date().toLocaleDateString("en-CA");
const anonymousId = getOrCreateAnonymousId();
const res = await fetch('/api/daily-verse', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ date: localDate, anonymousId }),
});
const result = await res.json();
return {
...data,
dailyVerse: result.dailyVerse,
correctBookId: result.correctBookId,
correctBook: result.correctBook,
};
};