mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
this is mainly just so any ip headers like cf-connecting-ip are forwarded for rate limiting
21 lines
671 B
TypeScript
21 lines
671 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import type { Paste } from '$lib/types/paste';
|
|
import { extractError } from '$lib/utils/misc';
|
|
import { error } from '@sveltejs/kit';
|
|
|
|
export const load: PageServerLoad = async ({ fetch, request }) => {
|
|
try {
|
|
const headers = new Headers(request.headers);
|
|
const res = await fetch('/api/paste/recent', { headers });
|
|
if (!res.ok) {
|
|
const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.';
|
|
throw error(res.status, errorMsg);
|
|
}
|
|
const recentPastes: Paste[] = await res.json();
|
|
return { recentPastes };
|
|
} catch (error) {
|
|
console.error(error);
|
|
return { recentPastes: [] };
|
|
}
|
|
};
|