From c8d0d1e959c77f4cd8a1aeeecd63abc241c52c41 Mon Sep 17 00:00:00 2001 From: Daniel Kluge Date: Mon, 3 Oct 2022 01:20:17 +0200 Subject: [PATCH] Use SSR --- docker-compose.dev.yml | 2 ++ docker-compose.stable.yml | 2 ++ pages/index.tsx | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 77a4bda..9aeb79e 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -23,6 +23,8 @@ services: - "traefik.http.routers.website-dev-secure.tls.certresolver=le" - "traefik.http.routers.website-dev-secure.service=website-dev" - "traefik.http.services.website-dev.loadbalancer.server.port=3000" + environment: + - BASE_URL=https://dev.c0ntroller.de networks: traefik: diff --git a/docker-compose.stable.yml b/docker-compose.stable.yml index 58fc1ea..808abc8 100644 --- a/docker-compose.stable.yml +++ b/docker-compose.stable.yml @@ -23,6 +23,8 @@ services: - "traefik.http.routers.website-stable-secure.tls.certresolver=le" - "traefik.http.routers.website-stable-secure.service=website-stable" - "traefik.http.services.website-stable.loadbalancer.server.port=3000" + environment: + - BASE_URL=https://c0ntroller.de networks: traefik: diff --git a/pages/index.tsx b/pages/index.tsx index 3f7f5b5..ec529f5 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -7,13 +7,13 @@ import ProjectCard from "../components/Blog/Card"; import Spinner from "../components/Spinner"; import styles from "../styles/Blog/Front.module.scss"; -const Blog: NextPage<{}> = () => { - const { data: projectList, error } = useSWR("/content/list.json", (...args) => fetch(...args).then(res => res.json())); +const Blog: NextPage<{ content: ContentList }> = ({content}) => { + //const { data: projectList, error } = useSWR("/content/list.json", (...args) => fetch(...args).then(res => res.json())); const generateCards = (type: string) => { - if (error) return
Error on fetching projects.
; - if (!projectList) return ; - else return
{(projectList as ContentList).filter(p => p.type === type).map(p => )}
; + //if (error) return
Error on fetching projects.
; + //if (!projectList) return ; + /*else*/ return
{content.filter(p => p.type === type).map(p => )}
; }; return <> @@ -37,4 +37,12 @@ const Blog: NextPage<{}> = () => { }; +export async function getServerSideProps() { + const url = process.env.BASE_URL || "https://c0ntroller.de"; + const res = await fetch(`${url}/content/list.json`); + const content = await res.json(); + + return { props: { content } }; +} + export default Blog; \ No newline at end of file