Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vercel): support bypassToken for on-demand static reganaration #1723

Merged
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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