Files
website/src/routes/trackers/cars/random/+page.server.ts

12 lines
552 B
TypeScript

import { redirect } from '@sveltejs/kit';
import { randomCar } from '#lib/server/cars.js';
import type { PageServerLoad } from './$types';
// A page load (not a +server.ts endpoint): the client router only knows page routes, so an
// endpoint here made client-side navigation fall through to the [brand] page and 404.
export const load: PageServerLoad = async ({ setHeaders }) => {
const car = await randomCar();
setHeaders({ 'cache-control': 'no-store' });
redirect(303, car ? `/trackers/cars/${car.brandSlug}/${car.slug}` : '/trackers/cars');
};