Skip to content

Commit

Permalink
(#34): Remove uri-parameter-dependent asset prefix, let next.config.j…
Browse files Browse the repository at this point in the history
…s handle it. Remove client rendered _draft, leave all rendering to SSR for now. Client uses useRouter, which appears to handle calls from XP proxy badly, specifically sets asPath wrong and causes error.
  • Loading branch information
espen42 committed Sep 14, 2021
1 parent 86d0731 commit 2b042dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 135 deletions.
53 changes: 0 additions & 53 deletions src/components/ClientSideBasePage.tsx

This file was deleted.

36 changes: 3 additions & 33 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -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 <>
<Head>
<base href={host} />
</Head>
<Component {...pageProps} />
</>;

} else {
return <Component {...pageProps} />
}
function MyApp({Component, pageProps}: AppProps) {
return <Component {...pageProps} />
}

export default MyApp
24 changes: 10 additions & 14 deletions src/pages/_draft/[[...contentPath]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 = () => <ClientSideBasePage branch={BRANCH} fetchContent={fetchContent} />;
export default ClientSidePage;
40 changes: 5 additions & 35 deletions src/pages/_master/[[...contentPath]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,22 @@ 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
},
__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 = () => <ClientSideBasePage branch={BRANCH} fetchContent={fetchContent} />;
export default ClientSidePage;
*/

0 comments on commit 2b042dd

Please sign in to comment.