diff --git a/docs/content/1.guide/4.storage.md b/docs/content/1.guide/4.storage.md index ed5354c8ba..fa2faeec85 100644 --- a/docs/content/1.guide/4.storage.md +++ b/docs/content/1.guide/4.storage.md @@ -58,6 +58,59 @@ export default defineNuxtConfig({ ``` :: + +### Runtime configuration + +In scenarios where the mount point configuration is not known until runtime, Nitro can dynamically add mount points during startup using [plugins](/guide/plugins): + +::alert{type="info"} +This is a temporary workaround, with a better solution coming in the future! Keep a lookout on the GitHub issue [here](https://github.com/unjs/nitro/issues/1161#issuecomment-1511444675). +:: + +::code-group +```ts [plugins/storage.ts] +import redisDriver from 'unstorage/drivers/redis' + +export default defineNitroPlugin(() => { + const storage = useStorage() + + // Dynamically pass in credentials from runtime configuration, or other sources + const driver = redisDriver({ + base: 'redis', + host: useRuntimeConfig().redis.host, + port: useRuntimeConfig().redis.port, + /* other redis connector options */ + }) + + // Mount driver + storage.mount('redis', driver) +}) +``` +``` ts [nitro.config.ts] +export default defineNitroConfig({ + runtimeConfig: { + redis: { // Default values + host: '', + port: 0, + /* other redis connector options */ + } + } +}) +``` +``` ts [nuxt.config.ts] +export default defineNuxtConfig({ + runtimeConfig: { + redis: { // Default values + host: '', + port: 0, + /* other redis connector options */ + } + } +}) +``` +:: + + Usage: ```js