Skip to content

Commit

Permalink
feat: add Vercel KV (#2533)
Browse files Browse the repository at this point in the history
  • Loading branch information
prplecake authored Jan 2, 2024
1 parent 77588c1 commit b016320
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NUXT_CLOUDFLARE_ACCOUNT_ID=
NUXT_CLOUDFLARE_NAMESPACE_ID=
NUXT_CLOUDFLARE_API_TOKEN=

# 'cloudflare' | 'fs'
# 'cloudflare' | 'vercel' | 'fs'
NUXT_STORAGE_DRIVER=
NUXT_STORAGE_FS_BASE=

Expand Down
6 changes: 6 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export default defineNuxtConfig({
namespaceId: '',
apiToken: '',
},
vercel: {
url: '',
token: '',
env: '',
base: '',
},
public: {
privacyPolicyUrl: '',
// We use LibreTranslate (https://github.com/LibreTranslate/LibreTranslate) as
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@tiptap/suggestion": "2.1.8",
"@tiptap/vue-3": "2.1.8",
"@unocss/nuxt": "^0.53.4",
"@upstash/redis": "^1.27.1",
"@vercel/kv": "^1.0.1",
"@vue-macros/nuxt": "^1.6.0",
"@vueuse/core": "^10.2.1",
"@vueuse/gesture": "2.0.0-beta.1",
Expand Down
83 changes: 55 additions & 28 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions server/utils/shared.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'unstorage/drivers/fs'
import memory from 'unstorage/drivers/memory'
import kv from 'unstorage/drivers/cloudflare-kv-http'
import vercelKVDriver from 'unstorage/drivers/vercel-kv'

import { $fetch } from 'ofetch'

Expand Down Expand Up @@ -29,6 +30,15 @@ else if (driver === 'cloudflare') {
apiToken: config.cloudflare.apiToken,
})))
}
else if (driver === 'vercel') {
const config = useRuntimeConfig()
storage.mount('servers', cached(vercelKVDriver({
url: config.vercel.url,
token: config.vercel.token,
env: config.vercel.env,
base: config.vercel.base,
})))
}
else if (driver === 'memory') {
storage.mount('servers', memory())
}
Expand Down

0 comments on commit b016320

Please sign in to comment.