diff --git a/src/components/ClientSideBasePage.tsx b/src/components/ClientSideBasePage.tsx deleted file mode 100644 index ecc9f591..00000000 --- a/src/components/ClientSideBasePage.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import React, {useEffect, useState} from "react"; -import {useRouter} from "next/router"; - -import {Branch, ContentResult} from "../shared/data/fetchContent"; -import BasePage, {BasePageProps} from "./BasePage"; - -type Props = { - branch: Branch, - fetchContent: (contentPath: string|string[], branch: Branch) => Promise> -}; - -const ClientSideBasePage = ({branch, fetchContent}: Props) => { - - const [props, setProps] = useState({error: undefined, content: {}, fetching: true}); - - const router = useRouter(); - const contentPath = router.query.contentPath; - - useEffect( - () => { - - // @ts-ignore - const refresh = async (contentPath) => { - setProps(props => ({...props, fetching: true})); - - const contentResult: BasePageProps = await fetchContent(contentPath, branch); - - //console.log("Fetched content result:", contentResult); - - // @ts-ignore - setProps(() => contentResult); - - // Simulate server delay - instead of the setProps line above: - /*setTimeout(() => { - // @ts-ignore - setProps(() => contentResult); - }, - 750);*/ - }; - - if (contentPath !== undefined) { - refresh(contentPath); - } - }, - [contentPath] - ); - - if (props.fetching) { - return

Fetching data...

- } - return ; -}; -export default ClientSideBasePage; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index c235157f..d6e7b9e6 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,38 +1,8 @@ import '../styles/globals.css' -import type { AppProps } from 'next/app' -import Head from 'next/head' +import type {AppProps} from 'next/app' - -function MyApp({ Component, pageProps }: AppProps) { - let host = pageProps.__host; - - - if (host) { - delete pageProps.__host; - - } else if ('undefined' !== typeof window) { - console.log('Hostin?'); - const urlParams = new URLSearchParams(window.location.search); - // @ts-ignore - if (urlParams && urlParams.get('__fromXp__') !== undefined) { - console.log('Hostin') - host = window.location.origin; - } - } - - console.log(host); - - if (host) { - return <> - - - - - ; - - } else { - return - } +function MyApp({Component, pageProps}: AppProps) { + return } export default MyApp diff --git a/src/pages/_draft/[[...contentPath]].tsx b/src/pages/_draft/[[...contentPath]].tsx index 8e2d0388..1a70909f 100644 --- a/src/pages/_draft/[[...contentPath]].tsx +++ b/src/pages/_draft/[[...contentPath]].tsx @@ -14,14 +14,22 @@ const fetchContent = buildContentFetcher({ const BRANCH = 'draft'; ////////////////////////////////////////////////////////////////////////////////////////////// SSR: uncomment this instead of CLIENT below -/* import BasePage from "../../components/BasePage"; type Context = { // this type is purposefully naive. Please make sure to update this with a more // accurate model before using it. - params: { contentPath: string[] }; + params: { contentPath: string[] } + /*req: { + headers: { + host: string, + referer?: string + }, + __NEXT_INIT_QUERY?: { + __fromXp__?: any + } + }*/ }; export const getServerSideProps = async ({params}: Context) => { @@ -31,15 +39,3 @@ export const getServerSideProps = async ({params}: Context) => { }; export default BasePage; - -*/ - - - -////////////////////////////////////////////////////////////////////////////////////////////// CLIENT: uncomment this instead of SSR above - - -import ClientSideBasePage from "../../components/ClientSideBasePage"; - -const ClientSidePage = () => ; -export default ClientSidePage; diff --git a/src/pages/_master/[[...contentPath]].tsx b/src/pages/_master/[[...contentPath]].tsx index 36044316..4b26ca37 100644 --- a/src/pages/_master/[[...contentPath]].tsx +++ b/src/pages/_master/[[...contentPath]].tsx @@ -20,7 +20,7 @@ type Context = { // this type is purposefully naive. Please make sure to update this with a more // accurate model before using it. params: { contentPath: string[] } - req: { + /*req: { headers: { host: string, referer?: string @@ -28,44 +28,14 @@ type Context = { __NEXT_INIT_QUERY?: { __fromXp__?: any } - } + }*/ }; -const getHost = (context: Context) => { - if (context?.req?.__NEXT_INIT_QUERY?.__fromXp__ !== undefined) { - console.log('Hostin') - const host = context?.req?.headers?.host; - const splitReferer = (context?.req?.headers?.referer || '').split('://'); - const protocol = (splitReferer || [])[0] || 'http'; // Defaults to http, assuming http auto-upgrades to https on most servers? - return `${protocol}://${host}` - } - - return undefined; -} export const getServerSideProps = async (context: Context) => { - const host = getHost(context); - - return (host) - ? { - props: { - ...await fetchContent(context.params.contentPath, BRANCH), - __host: host - } - } - : { - props: await fetchContent(context.params.contentPath, BRANCH) - } + return { + props: await fetchContent(context.params.contentPath, BRANCH) + } }; export default BasePage; - - -////////////////////////////////////////////////////////////////////////////////////////////// CLIENT: uncomment this instead of SSR above -/* - -import ClientSideBasePage from "../../components/ClientSideBasePage"; - -const ClientSidePage = () => ; -export default ClientSidePage; -*/