|
1 | 1 | --- |
2 | 2 | title: Configuration |
3 | | -description: Config reference, YAML example, and options for Dashboard |
| 3 | +description: Full config reference with all options, YAML example, validation rules, and functional options |
4 | 4 | --- |
5 | 5 |
|
6 | | -## YAML Configuration Example |
| 6 | +import { Callout } from 'fumadocs-ui/components/callout'; |
| 7 | + |
| 8 | +## YAML Configuration |
7 | 9 |
|
8 | 10 | ```yaml title="config.yaml" |
9 | 11 | extensions: |
10 | 12 | dashboard: |
11 | | - basePath: "/dashboard" |
12 | | - enableAuth: false |
13 | | - enableRealtime: true |
14 | | - enableExport: true |
15 | | - exportFormats: |
| 13 | + # Server |
| 14 | + base_path: "/dashboard" |
| 15 | + title: "Forge Dashboard" |
| 16 | + |
| 17 | + # Features |
| 18 | + enable_realtime: true |
| 19 | + enable_export: true |
| 20 | + enable_search: true |
| 21 | + enable_settings: true |
| 22 | + enable_discovery: false |
| 23 | + enable_bridge: true |
| 24 | + |
| 25 | + # Data collection |
| 26 | + refresh_interval: "30s" |
| 27 | + history_duration: "1h" |
| 28 | + max_data_points: 1000 |
| 29 | + |
| 30 | + # Proxy / Remote contributors |
| 31 | + proxy_timeout: "10s" |
| 32 | + cache_max_size: 1000 |
| 33 | + cache_ttl: "30s" |
| 34 | + |
| 35 | + # SSE |
| 36 | + sse_keep_alive: "15s" |
| 37 | + |
| 38 | + # Security |
| 39 | + enable_csp: true |
| 40 | + enable_csrf: true |
| 41 | + |
| 42 | + # Theming |
| 43 | + theme: "auto" # "auto", "light", "dark" |
| 44 | + custom_css: "" |
| 45 | + |
| 46 | + # Discovery |
| 47 | + discovery_tag: "forge-dashboard-contributor" |
| 48 | + discovery_poll_interval: "60s" |
| 49 | + |
| 50 | + # Export |
| 51 | + export_formats: |
16 | 52 | - "json" |
17 | 53 | - "csv" |
18 | 54 | - "prometheus" |
19 | | - refreshInterval: "30s" |
20 | | - historyDuration: "1h" |
21 | | - maxDataPoints: 1000 |
22 | | - theme: "auto" # "auto", "light", "dark" |
23 | | - title: "Forge Dashboard" |
24 | 55 | ``` |
25 | 56 |
|
26 | 57 | The extension loads config from `extensions.dashboard` first, falling back to `dashboard`. |
27 | 58 |
|
28 | 59 | ## Programmatic Configuration |
29 | 60 |
|
| 61 | +All options use the functional options pattern: |
| 62 | + |
30 | 63 | ```go |
31 | 64 | ext := dashboard.NewExtension( |
32 | 65 | dashboard.WithBasePath("/admin/dashboard"), |
| 66 | + dashboard.WithTitle("Admin Panel"), |
33 | 67 | dashboard.WithRealtime(true), |
34 | 68 | dashboard.WithExport(true), |
35 | | - dashboard.WithRefreshInterval(15 * time.Second), |
36 | | - dashboard.WithHistory(2*time.Hour, 2000), |
| 69 | + dashboard.WithSearch(true), |
| 70 | + dashboard.WithSettings(true), |
| 71 | + dashboard.WithBridge(true), |
| 72 | + dashboard.WithRefreshInterval(30 * time.Second), |
| 73 | + dashboard.WithHistoryDuration(2 * time.Hour), |
| 74 | + dashboard.WithMaxDataPoints(2000), |
| 75 | + dashboard.WithTheme("auto"), |
| 76 | + dashboard.WithCSP(true), |
| 77 | + dashboard.WithCSRF(true), |
37 | 78 | ) |
38 | 79 | ``` |
39 | 80 |
|
40 | | -## Config Struct Reference |
41 | | - |
42 | | -| Field | Type | Default | Description | |
43 | | -|---|---|---|---| |
44 | | -| `BasePath` | `string` | `"/dashboard"` | HTTP base path | |
45 | | -| `EnableAuth` | `bool` | `false` | Require authentication | |
46 | | -| `EnableRealtime` | `bool` | `true` | Enable WebSocket updates | |
47 | | -| `EnableExport` | `bool` | `true` | Enable data export endpoints | |
48 | | -| `ExportFormats` | `[]string` | `["json","csv","prometheus"]` | Available export formats | |
49 | | -| `RefreshInterval` | `time.Duration` | `30s` | Real-time update interval | |
50 | | -| `HistoryDuration` | `time.Duration` | `1h` | Metric history window | |
51 | | -| `MaxDataPoints` | `int` | `1000` | Max data points in history | |
52 | | -| `Theme` | `string` | `"auto"` | Dashboard theme | |
53 | | -| `Title` | `string` | `"Forge Dashboard"` | Dashboard page title | |
| 81 | +## Config Reference |
| 82 | + |
| 83 | +### Server |
| 84 | + |
| 85 | +| Field | Type | Default | Option | Description | |
| 86 | +|---|---|---|---|---| |
| 87 | +| `BasePath` | `string` | `"/dashboard"` | `WithBasePath()` | HTTP base path for all dashboard routes | |
| 88 | +| `Title` | `string` | `"Forge Dashboard"` | `WithTitle()` | Page title shown in browser tab and header | |
| 89 | + |
| 90 | +### Features |
| 91 | + |
| 92 | +| Field | Type | Default | Option | Description | |
| 93 | +|---|---|---|---|---| |
| 94 | +| `EnableRealtime` | `bool` | `true` | `WithRealtime()` | SSE real-time event stream | |
| 95 | +| `EnableExport` | `bool` | `true` | `WithExport()` | Data export endpoints (JSON, CSV, Prometheus) | |
| 96 | +| `EnableSearch` | `bool` | `true` | `WithSearch()` | Federated cross-contributor search | |
| 97 | +| `EnableSettings` | `bool` | `true` | `WithSettings()` | Aggregated settings page | |
| 98 | +| `EnableDiscovery` | `bool` | `false` | `WithDiscovery()` | Auto-discover remote contributors via service discovery | |
| 99 | +| `EnableBridge` | `bool` | `true` | `WithBridge()` | Go-JS bridge function system | |
| 100 | + |
| 101 | +### Data Collection |
| 102 | + |
| 103 | +| Field | Type | Default | Option | Description | |
| 104 | +|---|---|---|---|---| |
| 105 | +| `RefreshInterval` | `time.Duration` | `30s` | `WithRefreshInterval()` | How often to collect metrics and health data | |
| 106 | +| `HistoryDuration` | `time.Duration` | `1h` | `WithHistoryDuration()` | How long to retain historical data points | |
| 107 | +| `MaxDataPoints` | `int` | `1000` | `WithMaxDataPoints()` | Maximum number of data points in history | |
| 108 | + |
| 109 | +### Proxy / Remote Contributors |
| 110 | + |
| 111 | +| Field | Type | Default | Option | Description | |
| 112 | +|---|---|---|---|---| |
| 113 | +| `ProxyTimeout` | `time.Duration` | `10s` | `WithProxyTimeout()` | Timeout for requests to remote contributors | |
| 114 | +| `CacheMaxSize` | `int` | `1000` | `WithCacheMaxSize()` | Max entries in the fragment proxy LRU cache | |
| 115 | +| `CacheTTL` | `time.Duration` | `30s` | `WithCacheTTL()` | Time-to-live for cached remote fragments | |
| 116 | + |
| 117 | +### SSE |
| 118 | + |
| 119 | +| Field | Type | Default | Option | Description | |
| 120 | +|---|---|---|---|---| |
| 121 | +| `SSEKeepAlive` | `time.Duration` | `15s` | `WithSSEKeepAlive()` | Interval for SSE keep-alive pings | |
| 122 | + |
| 123 | +### Security |
| 124 | + |
| 125 | +| Field | Type | Default | Option | Description | |
| 126 | +|---|---|---|---|---| |
| 127 | +| `EnableCSP` | `bool` | `true` | `WithCSP()` | Add Content-Security-Policy headers | |
| 128 | +| `EnableCSRF` | `bool` | `true` | `WithCSRF()` | CSRF token protection for forms and bridge calls | |
| 129 | + |
| 130 | +### Theming |
| 131 | + |
| 132 | +| Field | Type | Default | Option | Description | |
| 133 | +|---|---|---|---|---| |
| 134 | +| `Theme` | `string` | `"auto"` | `WithTheme()` | Theme mode: `auto`, `light`, or `dark` | |
| 135 | +| `CustomCSS` | `string` | `""` | `WithCustomCSS()` | Custom CSS injected into the dashboard | |
| 136 | + |
| 137 | +### Discovery |
| 138 | + |
| 139 | +| Field | Type | Default | Option | Description | |
| 140 | +|---|---|---|---|---| |
| 141 | +| `DiscoveryTag` | `string` | `"forge-dashboard-contributor"` | `WithDiscoveryTag()` | Service discovery tag to filter contributors | |
| 142 | +| `DiscoveryPollInterval` | `time.Duration` | `60s` | `WithDiscoveryPollInterval()` | How often to poll for new remote contributors | |
| 143 | + |
| 144 | +### Export |
| 145 | + |
| 146 | +| Field | Type | Default | Option | Description | |
| 147 | +|---|---|---|---|---| |
| 148 | +| `ExportFormats` | `[]string` | `["json","csv","prometheus"]` | `WithExportFormats()` | Supported export formats | |
| 149 | + |
| 150 | +### Internal |
| 151 | + |
| 152 | +| Field | Type | Default | Option | Description | |
| 153 | +|---|---|---|---|---| |
| 154 | +| `RequireConfig` | `bool` | `false` | `WithRequireConfig()` | Require config from ConfigManager (fail if missing) | |
| 155 | + |
| 156 | +## Functional Options |
| 157 | + |
| 158 | +All options are available as `ConfigOption` functions: |
| 159 | + |
| 160 | +```go |
| 161 | +// Server |
| 162 | +dashboard.WithBasePath(path string) |
| 163 | +dashboard.WithTitle(title string) |
| 164 | +
|
| 165 | +// Features |
| 166 | +dashboard.WithRealtime(enabled bool) |
| 167 | +dashboard.WithExport(enabled bool) |
| 168 | +dashboard.WithSearch(enabled bool) |
| 169 | +dashboard.WithSettings(enabled bool) |
| 170 | +dashboard.WithDiscovery(enabled bool) |
| 171 | +dashboard.WithBridge(enabled bool) |
| 172 | +
|
| 173 | +// Data collection |
| 174 | +dashboard.WithRefreshInterval(interval time.Duration) |
| 175 | +dashboard.WithHistoryDuration(duration time.Duration) |
| 176 | +dashboard.WithMaxDataPoints(maxPoints int) |
| 177 | +
|
| 178 | +// Proxy |
| 179 | +dashboard.WithProxyTimeout(timeout time.Duration) |
| 180 | +dashboard.WithCacheMaxSize(size int) |
| 181 | +dashboard.WithCacheTTL(ttl time.Duration) |
| 182 | +
|
| 183 | +// SSE |
| 184 | +dashboard.WithSSEKeepAlive(interval time.Duration) |
| 185 | +
|
| 186 | +// Security |
| 187 | +dashboard.WithCSP(enabled bool) |
| 188 | +dashboard.WithCSRF(enabled bool) |
| 189 | +
|
| 190 | +// Theming |
| 191 | +dashboard.WithTheme(theme string) |
| 192 | +dashboard.WithCustomCSS(css string) |
| 193 | +
|
| 194 | +// Discovery |
| 195 | +dashboard.WithDiscoveryTag(tag string) |
| 196 | +dashboard.WithDiscoveryPollInterval(interval time.Duration) |
| 197 | +
|
| 198 | +// Export |
| 199 | +dashboard.WithExportFormats(formats []string) |
| 200 | +
|
| 201 | +// Advanced |
| 202 | +dashboard.WithConfig(config Config) // Set complete config |
| 203 | +dashboard.WithRequireConfig(required bool) // Require config from ConfigManager |
| 204 | +``` |
| 205 | + |
| 206 | +## Validation Rules |
| 207 | + |
| 208 | +The config is validated during `Register()`. The following constraints apply: |
| 209 | + |
| 210 | +| Field | Rule | |
| 211 | +|---|---| |
| 212 | +| `BasePath` | Must not be empty | |
| 213 | +| `RefreshInterval` | Minimum 1 second | |
| 214 | +| `MaxDataPoints` | Minimum 10 | |
| 215 | +| `Theme` | Must be `light`, `dark`, or `auto` | |
| 216 | +| `ProxyTimeout` | Minimum 1 second | |
| 217 | +| `CacheMaxSize` | Must not be negative | |
| 218 | + |
| 219 | +<Callout type="warn"> |
| 220 | +If validation fails, `Register()` returns an error and the dashboard will not start. |
| 221 | +</Callout> |
0 commit comments