feat: add /api/send-daily-verse endpoint for daily Discord verse posting

Protected by CRON_SECRET bearer token. Fetches today's verse in
America/New_York timezone and POSTs it to DISCORD_DAILY_WEBHOOK.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
George Powell
2026-03-22 00:57:01 -04:00
parent 45d33b6bad
commit 51bfb53a39

View File

@@ -0,0 +1,36 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { getVerseForDate } from '$lib/server/daily-verse';
import { CRON_SECRET, DISCORD_DAILY_WEBHOOK } from '$env/dynamic/private';
export const POST: RequestHandler = async ({ request }) => {
const authHeader = request.headers.get('Authorization');
if (!authHeader || authHeader !== `Bearer ${CRON_SECRET}`) {
return json({ error: 'Unauthorized' }, { status: 401 });
}
const dateStr = new Date().toLocaleDateString('en-CA', { timeZone: 'America/New_York' });
const verse = await getVerseForDate(dateStr);
const fullDate = new Date(dateStr + 'T00:00:00Z').toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
timeZone: 'UTC',
});
const message = `Today's BIBDLE Verse (${fullDate}): "${verse.verseText}" — ${verse.reference}`;
const discordResponse = await fetch(DISCORD_DAILY_WEBHOOK, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: message }),
});
if (!discordResponse.ok) {
return json({ error: 'Failed to post to Discord' }, { status: 500 });
}
return json({ ok: true });
};