thomaswilson-sveltekit/src/routes/api/blog/[slug].json.ts
2022-08-07 08:14:12 +01:00

20 lines
333 B
TypeScript

import { fetchBlogPostBySlug } from '$lib';
import type { LoadInput } from '@sveltejs/kit';
export const GET = async ({ params }: LoadInput) => {
const { slug } = params;
const post = await fetchBlogPostBySlug(slug);
if (!post) {
return {
status: 404,
body: {}
};
}
return {
status: 200,
body: { post }
};
};