Skip to content

Commit 3712de9

Browse files
S3Prototypestyfle
andauthoredMay 12, 2023
Update preview mode example to say draft mode (vercel#699)
### Description We're changing the name of Preview Mode to Draft mode. - [Next docs update](https://nextjs.org/docs/pages/building-your-application/configuring/draft-mode) Vercel docs updates are in the works. <!-- ✍️ Write a short summary of your work. Screenshots and videos are welcome! --> ### Demo URL <!-- Provide a URL to a live deployment where we can test your PR. If a demo isn't possible feel free to omit this section. --> ### Type of Change - [ ] New Example - [x] Example updates (Bug fixes, new features, etc.) - [ ] Other (changes to the codebase, but not to examples) ### New Example Checklist - [ ] 🛫 `npm run new-example` was used to create the example - [ ] 📚 The template wasn't used but I carefuly read the [Adding a new example](https://github.com/vercel/examples#adding-a-new-example) steps and implemented them in the example - [ ] 📱 Is it responsive? Are mobile and tablets considered? --------- Co-authored-by: Steven <[email protected]>
1 parent 542d735 commit 3712de9

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed
 

‎build-output-api/preview-mode/.vercel/output/functions/index.func/index.js ‎build-output-api/draft-mode/.vercel/output/functions/index.func/index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ const bypassToken = '87734ad8259d67c3c11747d3e4e112d0'
44

55
module.exports = (req, res) => {
66
res.setHeader('Content-Type', 'text/html; charset=utf-8')
7-
const isPreviewMode =
7+
const isDraftMode =
88
typeof req.headers.cookie === 'string' &&
99
req.headers.cookie.includes(`__prerender_bypass=${bypassToken}`)
10-
const contents = isPreviewMode
11-
? 'Preview Mode is <strong>ENABLED</strong>. Notice how the "Server time" below gets updated every time you refresh!'
12-
: 'Preview Mode is <strong>DISABLED</strong>. The "server time" below will only get updated once per minute.'
13-
const enable = isPreviewMode
14-
? '<a href="/logout">Deactivate Preview Mode</a>'
15-
: '<a href="/login">Enable Preview Mode</a>'
10+
const contents = isDraftMode
11+
? 'Draft Mode is <strong>ENABLED</strong>. Notice how the "Server time" below gets updated every time you refresh!'
12+
: 'Draft Mode is <strong>DISABLED</strong>. The "server time" below will only get updated once per minute.'
13+
const enable = isDraftMode
14+
? '<a href="/logout">Deactivate Draft Mode</a>'
15+
: '<a href="/login">Enable Draft Mode</a>'
1616
res.end(`
17-
<h1>Preview Mode Example</h1>
17+
<h1>Draft Mode Example</h1>
1818
<p>${contents}</p>
1919
<p>Server time: ${new Date().toISOString()}</p>
2020
<p>${enable}</p>

‎build-output-api/draft-mode/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Draft Mode
2+
3+
## Build Output API
4+
5+
This Prebuilt Deployment example demonstrates how to implement "Draft Mode" when using the [Build Output API](https://vercel.com/docs/build-output-api/v3#features/draft-mode).
6+
7+
### Demo
8+
9+
https://build-output-api-draft-mode.vercel.sh
10+
11+
### How it Works
12+
13+
When using Prerender Functions, you may want to implement "Draft Mode" which would allow you to bypass the caching
14+
aspect of prerender functions, i.e. while writing draft blog posts before they are ready to be published.
15+
16+
To implement this, the `bypassToken` of the [`<name>.prerender-config.json`](./.vercel/output/functions/index.prerender-config.json) file should be set to a randomized string that you generate at build-time. This string should not be exposed to users / the client-side, except under authenticated circumstances.
17+
18+
To enable "Draft Mode", a cookie with the name `__prerender_bypass` needs to be set (i.e. by a Serverless Function) with the value of the `bypassToken`. When the Prerender Function endpoint is accessed while the cookie is set, then "Draft Mode" will be activated, bypassing any caching that Vercel would normally provide when not in Draft Mode.

‎build-output-api/preview-mode/README.md

-18
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.