nuxt-modules / og-image

Generate OG Images with Vue templates in Nuxt.
https://nuxtseo.com/og-image
360 stars 23 forks source link

Is it possible to use runtime config for runtimeCacheStorage? #179

Open tberk opened 3 months ago

tberk commented 3 months ago

Hello currently I set runtime cache storage as so:

ogImage: {   
    runtimeCacheStorage: {
      driver: 'redis',
      host: process.env.NUXT_REDIS_HOST,
      port: 6379,
      ttlSeconds: 60 * 60 * 24 * 3,
      base: 'best-og',
      password: process.env.NUXT_REDIS_PASSWORD,
    },
  }

I also have a nitro plugin to register redis storage (Independent of og:image config)

export default defineNitroPlugin(() => {
  const storage = useStorage()
  const config = useRuntimeConfig()

  const driver = redisDriver({
    base: config.redis.base,
    host: config.redis.host,
    port: 6379,
    ttl: 60 * 60 * 24 * 3, // 3 days
    password: config.redis.password,
  })

  // Mount driver
  storage.mount('redis', driver)

  // https://nitro.unjs.io/guide/cache
  // Use redis on cache instead of memory
  await storage.unmount('cache')
  storage.mount('cache', driver)
})

Module works fine with above config however I was wondering if there is a better way of doing it.