nitro
nitro copied to clipboard
Storage mounts with dynamic configuration
Describe the feature
relates nuxt/nuxt#20195
The examples in the above discussions are fairly common, maybe provide a function to escape?
Additional information
- [X] Would you be willing to help implement this feature?
Configuration from nitro.config
and app.config
is serialized during building we cannot use dynamic configuration from there. I am thinking to support server/storage.ts
to make it possible or nitro.storage
in app.config
(however nuxt needs to tree-shake it first)
As a workaround, you can use a runtime plugin to mount in app context using plugins/storage.ts
(nuxt: server/plugins/storage.ts
)
import redis from "unstorage/drivers/redis";
export default defineNitroPlugin(() => {
const storage = useStorage();
storage.mount(
"/redis",
redis({
// ... options from runtime config, app config or process.env
})
);
});
If possible, I would still prefer to have some way of use process.env in config. like this nuxt/nuxt#18910 if I have many modules and want to use different default values on different environments, it would provide a better DX , without creating a bunch of plugins.
Would it be possible to document the temporary workaround as mentioned by @pi0 (https://github.com/unjs/nitro/issues/1161#issuecomment-1511444675) inside Nuxt documentation?
Would be happy to open a PR for this! Thanks (:
PR also welcome for nitro docs to mention workaround in storage section 👍🏼
Sorry for necro but is there a way to do this for the cache system too?
Currently, if I try to mount cache
in a plugin using pi0's way, i get ERROR [worker init] already mounted at cache
.
Is the only way here to override every single defineCachedEventHandler
to use a custom mount point (base)?
you might need to call .unmount()
first.