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

docs(vercel): add vercel kv storage section #1210

Merged
merged 3 commits into from
May 5, 2023
Merged
Changes from 1 commit
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
52 changes: 52 additions & 0 deletions docs/content/2.deploy/providers/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,58 @@ It is possible to deploy your nitro applications directly on [Vercel Edge Functi

In order to enable this target, please set `NITRO_PRESET` environment variable to `vercel-edge`.

## Vercel Storage

Nitro has built-in support for [Vercel KV storage](https://vercel.com/docs/storage/vercel-kv) and can be integrated with [Storage/Layer](/guide/storage).
danielroe marked this conversation as resolved.
Show resolved Hide resolved


pi0 marked this conversation as resolved.
Show resolved Hide resolved
### Usage

1. Install `@vercel/kv` as a dev dependency:

```json [package.json]
{
"devDependencies": {
"@vercel/kv": "latest"
}
}
```

Update your configuration:

::code-group
```ts [nitro.config.ts]
import { defineNitroConfig } from 'nitropack/config'

export default defineNitroConfig({
storage: {
data: { driver: 'vercelKV' }
}
})
```
```ts [nuxt.config.ts]
export default defineNuxtConfig({
storage: {
data: { driver: 'vercelKV' }
}
})
```
::

**Note:** You need to either set `KV_REST_API_URL` and `KV_REST_API_TOKEN` environment variables or pass `url` and `token` to driver options. Check [unstorage docs](https://unstorage.unjs.io/drivers/vercel-kv) for more information about driver usage.

You can now access data store in any event handler:

```ts
export default eventHandler(async (event) => {
const dataStorage = await useStorage("data");
await dataStorage.setItem("hello", "world");
return {
hello: await dataStorage.getItem("hello"),
};
});
```

## 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.