thomaswilson-sveltekit/src/routes/api/blog/[slug].json.ts

21 lines
333 B
TypeScript
Raw Normal View History

2022-04-16 10:43:45 +00:00
import { fetchBlogPostBySlug } from '$lib';
import type { LoadInput } from '@sveltejs/kit';
export const GET = async ({ params }: LoadInput) => {
2022-04-16 10:43:45 +00:00
const { slug } = params;
2022-04-16 10:50:44 +00:00
2022-04-16 10:43:45 +00:00
const post = await fetchBlogPostBySlug(slug);
if (!post) {
return {
status: 404,
body: {}
};
}
return {
status: 200,
body: { post }
};
};