-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1237 from vivid-planet/site-preview
Use Next.JS Site-Preview mode
- Loading branch information
Showing
34 changed files
with
239 additions
and
442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
"@comet/cms-admin": major | ||
"@comet/cms-api": major | ||
"@comet/eslint-config": minor | ||
"@comet/cms-site": minor | ||
--- | ||
|
||
Migrate site preview to Next.js Preview Mode | ||
|
||
Requires following changes to site: | ||
|
||
- Import `useRouter` from `next/router` (not exported from `@comet/cms-site` anymore) | ||
- Import `Link` from `next/link` (not exported from `@comet/cms-site` anymore) | ||
- Remove preview pages (pages in `src/pages/preview/` directory which call `createGetUniversalProps` with preview parameters) | ||
- Remove `createGetUniversalProps` | ||
- Just implement `getStaticProps`/`getServerSideProps` (Preview Mode will SSR automatically) | ||
- Get `previewData` from `context` and use it to configure the GraphQL Client | ||
- Add `SitePreviewProvider` to `App` (typically in `src/pages/_app.tsx`) | ||
- Add `/api/preview` Next API route (see demo) | ||
|
||
Requires following changes to API: | ||
|
||
- Set `sitePreviewSecret` in `PageTreeModule`-options (make sure it's the same across multiple API-instances) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import createGraphQLClient, { GraphQLClientOptions } from "@src/util/createGraphQLClient"; | ||
import { gql } from "graphql-request"; | ||
|
||
import { GQLValidateSitePreviewHashQuery, GQLValidateSitePreviewHashQueryVariables } from "./preview.generated"; | ||
|
||
export default async function handler(req, res) { | ||
const data = await createGraphQLClient().request<GQLValidateSitePreviewHashQuery, GQLValidateSitePreviewHashQueryVariables>( | ||
gql` | ||
query ValidateSitePreviewHash($timestamp: Float!, $hash: String!) { | ||
validateSitePreviewHash(timestamp: $timestamp, hash: $hash) | ||
} | ||
`, | ||
{ | ||
timestamp: parseInt(req.query.timestamp), | ||
hash: req.query.hash, | ||
}, | ||
); | ||
if (!data.validateSitePreviewHash) { | ||
return res.status(401).json({ message: "Validation failed" }); | ||
} | ||
|
||
const previewData: PreviewData = { | ||
includeInvisiblePages: true, | ||
includeInvisibleBlocks: req.query.includeInvisibleBlocks === "true", | ||
previewDamUrls: true, | ||
}; | ||
res.setPreviewData(previewData); | ||
res.redirect(req.query.path ?? "/"); | ||
} | ||
|
||
export type PreviewData = GraphQLClientOptions; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.