Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/content/1.get-started/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,27 @@ Generates:
```

Both usage and output are simplified!

## `Runtime Variables`

You can update all the above options at runtime by adding your configs as `runtimeConfig.public.ipx` key in `nuxt.config.ts`.
This plugin will merge your injected variables with the module options.

```ts [nuxt.config.ts]
export default defineNuxtConfig({
// ...
runtimeConfig: {
// ...
public: {
// ...
ipx: {
// All the above properties can be added here.
alias: process.env.NUXT_PUBLIC_IPX_ALIAS,
http: {
domains: process.env.NUXT_PUBLIC_IPX_HTTP_DOMAINS,
},
},
},
},
})
```
7 changes: 6 additions & 1 deletion src/runtime/ipx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import type { IPXOptions } from 'ipx'
import { lazyEventHandler, useBase } from 'h3'
import { isAbsolute } from 'pathe'
import type { NitroRuntimeConfig } from 'nitropack'
import { defu } from 'defu'

import { useRuntimeConfig } from '#imports'

export default lazyEventHandler(() => {
const opts = useRuntimeConfig().ipx as NitroRuntimeConfig['ipx'] || {} as Record<string, never>
let opts = useRuntimeConfig().ipx as NitroRuntimeConfig['ipx'] || {} as Record<string, never>
const publicOpts = useRuntimeConfig().public.ipx as NitroRuntimeConfig['ipx'] || {} as Record<string, never>

// use NUXT_PUBLIC_IPX_* environment variables for updating options in runtime
opts = defu(publicOpts, opts)

// TODO: Migrate to unstorage layer
const fsDir = opts?.fs?.dir ? (Array.isArray(opts.fs.dir) ? opts.fs.dir : [opts.fs.dir]).map(dir => isAbsolute(dir) ? dir : fileURLToPath(new URL(dir, import.meta.url))) : undefined
Expand Down