Skip to content

Commit

Permalink
Merge pull request #10740 from wellcomecollection/revert-10739-revert…
Browse files Browse the repository at this point in the history
…-10721-next-preview

Trial Prismic's next preview tool, part II
  • Loading branch information
rcantin-w authored Apr 10, 2024
2 parents 1576873 + 1587a9d commit 9266957
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 44 deletions.
4 changes: 0 additions & 4 deletions common/koa-middleware/withCachedValues.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import compose from 'koa-compose';
import { withPrismicPreviewStatus } from './withPrismicPreviewStatus';
import { IncomingMessage, ServerResponse } from 'http';
import Router from 'koa-router';
import { NextServer } from 'next/dist/server/next';
import { parse, UrlWithParsedQuery } from 'url'; // eslint-disable-line n/no-deprecated-api

export const withCachedValues = compose([withPrismicPreviewStatus]);

export async function route(
path: string,
page: string,
Expand Down
27 changes: 0 additions & 27 deletions common/koa-middleware/withPrismicPreviewStatus.ts

This file was deleted.

2 changes: 1 addition & 1 deletion common/views/components/CivicUK/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const necessaryCookies = () => {
const wcCookies = Object.values(cookies).map(c => c);

// Allows Prismic previews
const prismicPreview = ['io.prismic.preview', 'isPreview'];
const prismicPreview = ['io.prismic.preview'];

// See @weco/toggles/webapp/toggles for details on each
const featureFlags = ['toggle_*'];
Expand Down
6 changes: 3 additions & 3 deletions common/views/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NextPage } from 'next';
import { AppProps } from 'next/app';
import React, { useEffect, FunctionComponent, ReactElement } from 'react';
import { ThemeProvider } from 'styled-components';
import { PrismicPreview } from '@prismicio/next';
import theme, { GlobalStyle } from '@weco/common/views/themes/default';
import LoadingIndicator from '@weco/common/views/components/LoadingIndicator/LoadingIndicator';
import { AppContextProvider } from '@weco/common/views/components/AppContext/AppContext';
Expand All @@ -20,7 +21,6 @@ import { ServerDataContext } from '@weco/common/server-data/Context';
import UserProvider from '@weco/common/views/components/UserProvider/UserProvider';
import { ApmContextProvider } from '@weco/common/views/components/ApmContext/ApmContext';
import { AppErrorProps } from '@weco/common/services/app';
import usePrismicPreview from '@weco/common/services/app/usePrismicPreview';
import useMaintainPageHeight from '@weco/common/services/app/useMaintainPageHeight';
import { GaDimensions } from '@weco/common/services/app/google-analytics';
import { deserialiseProps } from '@weco/common/utils/json';
Expand Down Expand Up @@ -126,8 +126,6 @@ const WecoApp: FunctionComponent<WecoAppProps> = ({
// or when requested client-side through next/link or next/router
// i.e. everything that we consider to be a page view

usePrismicPreview(() => Boolean(document.cookie.match('isPreview=true')));

const getLayout = Component.getLayout || (page => <>{page}</>);

return (
Expand Down Expand Up @@ -157,6 +155,8 @@ const WecoApp: FunctionComponent<WecoAppProps> = ({
title={pageProps.err.message}
/>
)}

<PrismicPreview repositoryName="wellcomecollection" />
</ThemeProvider>
</SearchContextProvider>
</AppContextProvider>
Expand Down
10 changes: 1 addition & 9 deletions content/webapp/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import Router from 'koa-router';
import next from 'next';
import { apmErrorMiddleware } from '@weco/common/services/apm/errorMiddleware';
import { init as initServerData } from '@weco/common/server-data';
import {
withCachedValues,
handleAllRoute,
} from '@weco/common/koa-middleware/withCachedValues';
import { handleAllRoute } from '@weco/common/koa-middleware/withCachedValues';
import linkResolver from '@weco/common/services/prismic/link-resolver';
import { createClient as createPrismicClient } from '@weco/common/services/prismic/fetch';
import * as prismic from '@prismicio/client';
Expand Down Expand Up @@ -44,7 +41,6 @@ const appPromise = nextApp
});

koaApp.use(apmErrorMiddleware);
koaApp.use(withCachedValues);

// Add a naive healthcheck endpoint for the load balancer
router.get('/management/healthcheck', async ctx => {
Expand Down Expand Up @@ -72,10 +68,6 @@ const appPromise = nextApp
defaultURL: '/',
});

ctx.cookies.set('isPreview', 'true', {
httpOnly: false,
});

ctx.redirect(url);
});

Expand Down

0 comments on commit 9266957

Please sign in to comment.