Basic post display
This commit is contained in:
15
src/routes/api/posts/+server.ts
Normal file
15
src/routes/api/posts/+server.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { getPosts } from '$lib/server/db';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
export const GET = (async ({ url }) => {
|
||||
const since = url.searchParams.get('since');
|
||||
let count = Number.parseInt(url.searchParams.get('count') || '');
|
||||
if (isNaN(count)) {
|
||||
count = 20;
|
||||
}
|
||||
count = Math.min(count, 100);
|
||||
const posts = await getPosts(since, count);
|
||||
return json(posts);
|
||||
}) satisfies RequestHandler;
|
Reference in New Issue
Block a user