You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/guides/fetch.mdx
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,18 @@ export default defineConfig({
29
29
});
30
30
```
31
31
32
+
## Runtime base URL
33
+
34
+
For a host that is only known at runtime (for example `process.env.API_BASE_URL` in Node or `import.meta.env.VITE_*` in Vite), use `baseUrl.runtime` instead of a fixed string. The built-in fetch client embeds the expression in generated URL template literals, so you can keep using `override.fetch` options such as `runtimeValidation` and `includeHttpResponseReturnType` without a custom mutator.
35
+
36
+
```ts title="orval.config.ts"
37
+
baseUrl: {
38
+
runtime: 'process.env.API_BASE_URL',
39
+
},
40
+
```
41
+
42
+
See the [output `baseUrl` reference](/docs/reference/configuration/output#runtime) for `imports` and expressions such as `env.API_BASE_URL` from a shared module (for example `import { env } from '../../env'`). MSW mock host filtering uses the separate [`mock.baseUrl`](/docs/reference/configuration/output#mock-options) option.
Copy file name to clipboardExpand all lines: docs/content/docs/guides/set-base-url.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,10 @@ export default defineConfig({
44
44
});
45
45
```
46
46
47
+
## Runtime base URL
48
+
49
+
To resolve the API base URL when your app runs (for example from environment variables) while using Orval's generated fetch client and built-in `override.fetch` features, set [`baseUrl.runtime`](/docs/reference/configuration/output#runtime) in your output config. This is separate from [`mock.baseUrl`](/docs/reference/configuration/output#mock-options), which only affects generated MSW handlers.
Embed a JavaScript expression into generated request URLs so the same build can call different hosts at runtime (for example with Docker images and environment variables). The value is emitted inside template literals in generated clients; only use trusted expressions from your configuration.
241
+
242
+
```ts title="orval.config.ts"
243
+
exportdefaultdefineConfig({
244
+
petstore: {
245
+
output: {
246
+
baseUrl: {
247
+
runtime: 'process.env.API_BASE_URL',
248
+
},
249
+
},
250
+
},
251
+
});
252
+
```
253
+
254
+
#### runtime
255
+
256
+
**Type:**`String`
257
+
258
+
JavaScript expression used inside generated template literals for the request base URL. Set this to the expression only (for example `process.env.API_BASE_URL`), not including `` `${...}` ``; Orval wraps it for you.
259
+
260
+
#### imports
261
+
262
+
**Type:**`GeneratorImport[]`
263
+
264
+
Optional. When `runtime` references a symbol from another module, list the imports Orval should emit into generated clients. Paths are relative to the generated file, same idea as mutator imports. The `runtime` expression must be valid where the generated code runs (after those imports).
Or a named export used as an object (for example `import { env } from '../../env'` and `env.API_BASE_URL` in application code) — set `runtime` to that property access and import the object under `name`:
Read the base URL from the OpenAPI `servers` field instead of a fixed string. When `true`, Orval resolves it from the spec’s `servers` entry (optionally with `variables` and `index` below).
0 commit comments