mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
docs: add runtime storage configuration examples (#22189)
This commit is contained in:
parent
b8a282e115
commit
a6b4c3c9d8
@ -340,10 +340,12 @@ Never combine `next()` callback with a legacy middleware that is `async` or retu
|
||||
|
||||
### Server Storage
|
||||
|
||||
Nitro provides a cross-platform [storage layer](https://nitro.unjs.io/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`.
|
||||
Nitro provides a cross-platform [storage layer](https://nitro.unjs.io/guide/storage). In order to configure additional storage mount points, you can use `nitro.storage`, or [server plugins](#server-plugins).
|
||||
|
||||
#### Example: Using Redis
|
||||
|
||||
Using `nitro.storage`:
|
||||
|
||||
```ts [nuxt.config.ts]
|
||||
export default defineNuxtConfig({
|
||||
nitro: {
|
||||
@ -363,6 +365,43 @@ export default defineNuxtConfig({
|
||||
})
|
||||
```
|
||||
|
||||
Alternatively, using server plugins:
|
||||
|
||||
::code-group
|
||||
|
||||
```ts [server/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 [nuxt.config.ts]
|
||||
export default defineNuxtConfig({
|
||||
runtimeConfig: {
|
||||
redis: { // Default values
|
||||
host: '',
|
||||
port: 0,
|
||||
/* other redis connector options */
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
::
|
||||
|
||||
Create a new file in `server/api/test.post.ts`:
|
||||
|
||||
```ts [server/api/test.post.ts]
|
||||
|
Loading…
Reference in New Issue
Block a user