import { json, error } from '@sveltejs/kit'; import type { RequestHandler } from './$types'; import { env } from '$env/dynamic/private'; import { log } from '$lib/server/logger'; const SCRAPER_URL = env.SCRAPER_API_URL ?? 'http://localhost:8080'; /** * GET /api/ranking * Proxies to the Go scraper's /api/ranking endpoint. * Returns the top-ranked novels list as JSON. */ export const GET: RequestHandler = async () => { try { const res = await fetch(`${SCRAPER_URL}/api/ranking`); if (!res.ok) { log.error('api/ranking', 'scraper returned error', { status: res.status }); error(502, `Ranking fetch failed: ${res.status}`); } const data = await res.json(); return json(data); } catch (e) { if (e instanceof Error && 'status' in e) throw e; log.error('api/ranking', 'network error', { err: String(e) }); error(502, 'Could not load ranking'); } };