16 lines
613 B
TypeScript
16 lines
613 B
TypeScript
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; }
|
|
}
|