[READ-ONLY] a fast, modern browser for the npm registry
at main 47 lines 1.3 kB view raw
1import process from 'node:process' 2import { defineNuxtModule, useRuntimeConfig } from 'nuxt/kit' 3import { provider } from 'std-env' 4 5// Storage key for fetch cache - must match shared/utils/fetch-cache-config.ts 6const FETCH_CACHE_STORAGE_BASE = 'fetch-cache' 7 8export default defineNuxtModule({ 9 meta: { 10 name: 'vercel-cache', 11 }, 12 setup(_, nuxt) { 13 if (provider !== 'vercel') { 14 return 15 } 16 17 const config = useRuntimeConfig() 18 19 nuxt.hook('nitro:config', nitroConfig => { 20 nitroConfig.storage = nitroConfig.storage || {} 21 22 const upstash = { 23 driver: 'upstash' as const, 24 url: config.upstash.redisRestUrl, 25 token: config.upstash.redisRestToken, 26 } 27 28 if (process.env.RUNTIME_CACHE) { 29 // Main cache storage (for defineCachedFunction, etc.) 30 nitroConfig.storage.cache = { 31 ...nitroConfig.storage.cache, 32 driver: 'vercel-runtime-cache', 33 } 34 35 // Fetch cache storage (for SWR fetch caching) 36 nitroConfig.storage[FETCH_CACHE_STORAGE_BASE] = { 37 ...nitroConfig.storage[FETCH_CACHE_STORAGE_BASE], 38 driver: 'vercel-runtime-cache', 39 } 40 } 41 42 const env = process.env.VERCEL_ENV 43 nitroConfig.storage.atproto = 44 env === 'production' ? upstash : { driver: 'vercel-runtime-cache' } 45 }) 46 }, 47})