Skip to content

Commit

Permalink
feat(vercel): support bypassToken for on-demand static reganaration (
Browse files Browse the repository at this point in the history
  • Loading branch information
hcmlopes authored Oct 5, 2023
1 parent 3f07e05 commit b42a432
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/content/2.deploy/providers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <bypassToken>. 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.
1 change: 1 addition & 0 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface VercelBuildConfigV3 {
}
>;
cache?: string[];
bypassToken?: string;
crons?: {
path: string;
schedule: string;
Expand Down

0 comments on commit b42a432

Please sign in to comment.