From 5b7fd8c28eb151e5fe84dc75f1e25a4761dca328 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Sun, 30 Aug 2020 20:59:36 -0500 Subject: [PATCH 1/2] Added API Routes to preview mode docs --- docs/advanced-features/preview-mode.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md index 1e8467620cf3b..f887bc2b4e6a2 100644 --- a/docs/advanced-features/preview-mode.md +++ b/docs/advanced-features/preview-mode.md @@ -203,6 +203,18 @@ You can pass an object to `setPreviewData` and have it be available in `getStati The preview mode works on `getServerSideProps` as well. It will also be available on the `context` object containing `preview` and `previewData`. +### Works with API Routes + +API Routes will have access to `preview` and `previewData` under the request object. For example: + +```js +export default function route(req, res) { + const isPreview = req.preview + const previewData = req.previewData + // ... +} +``` + ### Unique per `next build` Both the bypass cookie value and the private key for encrypting the `previewData` change when `next build` is completed. From b3bab22ee8755fb7bdab9c8e4f47dfb40999d503 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Sun, 30 Aug 2020 21:01:47 -0500 Subject: [PATCH 2/2] changed function name --- docs/advanced-features/preview-mode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md index f887bc2b4e6a2..a1b05fb09c651 100644 --- a/docs/advanced-features/preview-mode.md +++ b/docs/advanced-features/preview-mode.md @@ -208,7 +208,7 @@ The preview mode works on `getServerSideProps` as well. It will also be availabl API Routes will have access to `preview` and `previewData` under the request object. For example: ```js -export default function route(req, res) { +export default function myApiRoute(req, res) { const isPreview = req.preview const previewData = req.previewData // ...