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

Unable to dynamically add a driver for a storage named cache in a plugin #2674

Open
censujiang opened this issue Aug 19, 2024 · 1 comment
Open

Comments

@censujiang
Copy link

Environment

  • Nitro: latest
  • Node: 20

Reproduction

https://stackblitz.com/edit/github-sbrgxd?file=server%2Fplugins%2Fstorage.ts

Describe the bug

As the title indicates, as long as the driver name is cache, an error will occur during the build or dev.

#1161 (comment)

Additional context

The problem occurs in the build phase of my Nuxt App, but not in the dev phase of the Nitro copy I provided

Logs

ERROR  [nuxt] [request error] [unhandled] [500] Cannot access 'nitroApp' before initialization                                                                                                                                          20:03:46  
  at Object.onRequest (/D:/my-nuxt-template/.nuxt/prerender/chunks/runtime.mjs:6801:7)
  at Object.handler (/D:/my-nuxt-template/node_modules/h3/dist/index.mjs:1959:21)
  at toNodeHandle (/D:/my-nuxt-template/node_modules/h3/dist/index.mjs:2266:17)
  at callHandle (/D:/my-nuxt-template/node_modules/unenv/runtime/fetch/call.mjs:25:12)
  at ufetch (/D:/my-nuxt-template/node_modules/unenv/runtime/fetch/index.mjs:9:23)
  at Object.localFetch (/D:/my-nuxt-template/.nuxt/prerender/chunks/runtime.mjs:6821:39)
  at /D:/my-nuxt-template/.nuxt/prerender/chunks/runtime.mjs:3162:36
`
@censujiang
Copy link
Author

key code:

import redisDriver from 'unstorage/drivers/redis'
import azureAppConfigurationDriver from 'unstorage/drivers/azure-app-configuration'

export default defineNitroPlugin((nuxtApp) => {
  const storage = useStorage()
  if (useRuntimeConfig().systemRuntimeType == 'azure') {
    storage.unmount('cache')
    const azure = azureAppConfigurationDriver({
      prefix: "default",
      label: "cache",
    })
    storage.mount('cache', azure)
  } else {
    storage.unmount('cache')
    const redis = redisDriver({
      url: "redis://localhost:6379",
    })
    storage.mount('cache', redis)
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant