From b42a432c65e2736c7f3526542dcfbbfa1608d75c Mon Sep 17 00:00:00 2001 From: Henrique Lopes <20449158+hcmlopes@users.noreply.github.com> Date: Thu, 5 Oct 2023 14:21:59 -0400 Subject: [PATCH] feat(vercel): support `bypassToken` for on-demand static reganaration (#1723) --- 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..5fc85caae5 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: + +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.VERCEL_BYPASS_TOKEN + } + } + }) + ``` + ```ts [nuxt.config.ts] + export default defineNuxtConfig({ + nitro: { + vercel: { + config: { + bypassToken: process.env.VERCEL_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;