Render thread pages on the server
This commit is contained in:
parent
40e0be35d9
commit
c23428f904
4 changed files with 32 additions and 3 deletions
13
src/routes/api/thread/[id]/+server.ts
Normal file
13
src/routes/api/thread/[id]/+server.ts
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
import { error, json } from "@sveltejs/kit";
|
||||
import { GROUP_ID } from "$lib/config";
|
||||
import { fetchThread, threadAuthors } from "$lib/forum/thread";
|
||||
import { fetchProfiles } from "$lib/forum/profiles";
|
||||
import { forumQuery, profileQuery } from "$lib/ssr/relay";
|
||||
|
||||
export async function GET({ params }) {
|
||||
if (!/^[0-9a-f]{64}$/.test(params.id)) error(404, "Not found");
|
||||
const thread = await fetchThread(forumQuery, params.id, GROUP_ID);
|
||||
if (!thread) error(404, "Not found");
|
||||
const profiles = await fetchProfiles(profileQuery, threadAuthors(thread));
|
||||
return json({ thread, profiles });
|
||||
}
|
||||
10
src/routes/thread/[id]/+page.ts
Normal file
10
src/routes/thread/[id]/+page.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { snapshot, type Profiles } from "$lib/forum/snapshot";
|
||||
import type { ThreadDetail } from "$lib/forum/thread";
|
||||
|
||||
export async function load({ fetch, params }) {
|
||||
const data = await snapshot<{ thread: ThreadDetail; profiles: Profiles }>(
|
||||
fetch,
|
||||
`/api/thread/${params.id}`,
|
||||
);
|
||||
return { thread: data?.thread ?? null, profiles: data?.profiles ?? null };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue