feat: render portfolio routes from live localized database content
This commit is contained in:
15
src/server/public.ts
Normal file
15
src/server/public.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'server-only';
|
||||
import { cache } from 'react';
|
||||
import { connection } from 'next/server';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { getDatabase } from './db';
|
||||
import { ContentError, readContent, resolvePublicRoute } from './content';
|
||||
|
||||
export const readPublicSnapshot = cache(async () => {
|
||||
await connection();
|
||||
return readContent(getDatabase());
|
||||
});
|
||||
export async function getPublicRoute(segments: string[] = []) {
|
||||
try { return resolvePublicRoute(await readPublicSnapshot(), segments); }
|
||||
catch (error) { if (error instanceof ContentError && error.status === 404) notFound(); throw error; }
|
||||
}
|
||||
Reference in New Issue
Block a user