shack/pages/shelves/shelf.page.server.js

26 lines
628 B
JavaScript

import { RenderErrorPage } from 'vite-plugin-ssr/RenderErrorPage';
import { fetchShelf } from '../../src/shelves';
import { fetchShelfPosts } from '../../src/posts';
async function getPageData(pageContext) {
const shelf = await fetchShelf(pageContext.routeParams.id, { user: pageContext.session.user });
const posts = await fetchShelfPosts(pageContext.routeParams.id, { user: pageContext.session.user, limit: 50 });
if (!shelf) {
throw RenderErrorPage({
pageContext: {
pageProps: {
errorInfo: 'No shelf with this name exists',
},
},
});
}
return {
shelf,
posts,
};
}
export { getPageData };