From c9c4f7ec3277c5c43cb609d75baabef574a152cf Mon Sep 17 00:00:00 2001 From: Henrique Lopes Date: Tue, 12 Sep 2023 15:58:52 -0400 Subject: [PATCH 1/3] feat(vercel-preset): adds on-demant ISR support --- docs/content/2.deploy/providers/vercel.md | 36 +++++++++++++++++++++++ src/presets/vercel.ts | 1 + src/types/presets.ts | 1 + 3 files changed, 38 insertions(+) diff --git a/docs/content/2.deploy/providers/vercel.md b/docs/content/2.deploy/providers/vercel.md index 7da9336807..4e2c0380c6 100644 --- a/docs/content/2.deploy/providers/vercel.md +++ b/docs/content/2.deploy/providers/vercel.md @@ -101,3 +101,39 @@ Instead, you have to use : ## Custom Build Output Configuration You can provide additional [build output configuration](https://vercel.com/docs/build-output-api/v3) using `vercel.config` key inside `nitro.config`. It will be merged with built-in auto generated config. + +## On-Demand Incremental Static Regeneration (ISR) + +On-demand revalidation allows you to purge the cache for an ISR route whenever you want, foregoing the time interval required with background revalidation. + +To revalidate a page on demand with Next.js: + +1. Create an Environment Variable which will store a revalidation secret + * You can use the command `openssl rand -base64 32` or https://generate-secret.vercel.app/32 to generate a random value. + +2. Update your configuration: + + ::code-group + ```ts [nitro.config.ts] + export default defineNitroConfig({ + vercel: { + config: { + bypassToken: process.env.BYPASS_TOKEN + } + } + }) + ``` + ```ts [nuxt.config.ts] + export default defineNuxtConfig({ + nitro: { + vercel: { + config: { + bypassToken: process.env.BYPASS_TOKEN + } + } + } + }) + ``` + :: + +3. To trigger "On-Demand Incremental Static Regeneration (ISR)" and revalidate a path to a Prerender Function, make a GET or HEAD request to that path with a header of x-prerender-revalidate: . When that Prerender Function endpoint is accessed with this header set, the cache will be revalidated. The next request to that function should return a fresh response. \ No newline at end of file diff --git a/src/presets/vercel.ts b/src/presets/vercel.ts index 176875025b..0d7bab7fd3 100644 --- a/src/presets/vercel.ts +++ b/src/presets/vercel.ts @@ -72,6 +72,7 @@ export const vercel = defineNitroPreset({ JSON.stringify({ expiration: value.isr === true ? false : value.isr, allowQuery: key.includes("/**") ? ["url"] : undefined, + bypassToken: nitro.options.vercel?.config?.bypassToken, }) ); } diff --git a/src/types/presets.ts b/src/types/presets.ts index fafccee23c..713fcf25bb 100644 --- a/src/types/presets.ts +++ b/src/types/presets.ts @@ -50,6 +50,7 @@ export interface VercelBuildConfigV3 { } >; cache?: string[]; + bypassToken?: string; crons?: { path: string; schedule: string; From 2923a26c8167b0a985055eb622f2bb4a1fbc21c6 Mon Sep 17 00:00:00 2001 From: Henrique Lopes Date: Wed, 13 Sep 2023 02:28:02 -0400 Subject: [PATCH 2/3] chore: fix documentation for on demand ISR --- docs/content/2.deploy/providers/vercel.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/2.deploy/providers/vercel.md b/docs/content/2.deploy/providers/vercel.md index 4e2c0380c6..3939c82946 100644 --- a/docs/content/2.deploy/providers/vercel.md +++ b/docs/content/2.deploy/providers/vercel.md @@ -106,7 +106,7 @@ You can provide additional [build output configuration](https://vercel.com/docs/ On-demand revalidation allows you to purge the cache for an ISR route whenever you want, foregoing the time interval required with background revalidation. -To revalidate a page on demand with Next.js: +To revalidate a page on demand: 1. Create an Environment Variable which will store a revalidation secret * You can use the command `openssl rand -base64 32` or https://generate-secret.vercel.app/32 to generate a random value. @@ -118,7 +118,7 @@ To revalidate a page on demand with Next.js: export default defineNitroConfig({ vercel: { config: { - bypassToken: process.env.BYPASS_TOKEN + bypassToken: process.env.VERCEL_BYPASS_TOKEN } } }) From fb442690e3d2f74fdc4b3a68127248d9879df5fa Mon Sep 17 00:00:00 2001 From: Henrique Lopes Date: Wed, 13 Sep 2023 02:31:23 -0400 Subject: [PATCH 3/3] chore: fix environment variable example in docs --- docs/content/2.deploy/providers/vercel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/2.deploy/providers/vercel.md b/docs/content/2.deploy/providers/vercel.md index 3939c82946..5fc85caae5 100644 --- a/docs/content/2.deploy/providers/vercel.md +++ b/docs/content/2.deploy/providers/vercel.md @@ -128,7 +128,7 @@ To revalidate a page on demand: nitro: { vercel: { config: { - bypassToken: process.env.BYPASS_TOKEN + bypassToken: process.env.VERCEL_BYPASS_TOKEN } } }