From 29a4e2488151861c10abeb0a05622e4d06e07c60 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Thu, 5 Dec 2019 17:34:44 +0100 Subject: Fix SSR on PostList --- components/Posts/PostList/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'components/Posts/PostList/index.js') diff --git a/components/Posts/PostList/index.js b/components/Posts/PostList/index.js index dbb515e..11d44ff 100644 --- a/components/Posts/PostList/index.js +++ b/components/Posts/PostList/index.js @@ -1,3 +1,22 @@ +import axios from 'axios' + +import k from '~/api' import PostList from './PostList' +export const getPosts = async () => { + if (process.client) { + let posts = await axios.get(`${window.location.origin}/api/posts.json`) + return parsePosts(posts.data) + } else { + return parsePosts(k.getPosts()) + } +} + +export const parsePosts = posts => + posts.map(post => ({ + title: post.content.meta.title, + description: post.content.description, + route: post.route + })) + export default PostList -- cgit 1.4.1