webapp/src/pages/article.page.server.ts

22 lines
547 B
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import type { PageContext } from '../renderer/types'
import type { PageProps } from './types'
import { apiClient } from '../utils/apiClient'
import { RenderErrorPage } from 'vite-plugin-ssr/RenderErrorPage'
2023-02-17 09:21:02 +00:00
export const onBeforeRender = async (pageContext: PageContext) => {
const { slug } = pageContext.routeParams
2023-05-08 17:21:06 +00:00
const article = await apiClient.getShoutBySlug(slug)
2023-02-17 09:21:02 +00:00
if (!article) {
throw RenderErrorPage({ pageContext: {} })
}
2023-02-17 09:21:02 +00:00
const pageProps: PageProps = { article }
return {
pageContext: {
pageProps
}
}
}