boredgame/src/routes/game/[id]/+page.server.ts

32 lines
630 B
TypeScript
Raw Normal View History

2022-08-26 05:06:39 +00:00
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
import { boardGameApi } from '../../api';
2022-04-20 02:15:46 +00:00
2022-08-24 20:36:40 +00:00
type GamePageParams = {
params: {
id: string;
};
};
export const load: PageServerLoad = async ({ params, setHeaders }: GamePageParams) => {
const queryParams = {
ids: `${params?.id}`
};
const response = await boardGameApi('get', `search`, queryParams);
if (response.status === 200) {
const gameResponse = await response.json();
2022-08-24 20:36:40 +00:00
setHeaders({
'Cache-Control': 'max-age=3600'
});
2022-04-20 02:15:46 +00:00
return {
game: gameResponse?.games[0]
};
}
2022-04-20 02:15:46 +00:00
throw error(response.status, 'not found');
2022-07-28 00:05:54 +00:00
};