Skip to content

Commit 8fac702

Browse files
amnirNir
authored andcommitted
fix(devcontainer): make Config UI and Grafana accessible from host when using devcontainers
1 parent 099576b commit 8fac702

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*
1717
*/
18-
1918
{
2019
"name": "Go",
2120
"dockerComposeFile": "docker-compose.yml",
@@ -36,6 +35,10 @@
3635
4000,
3736
8080
3837
],
38+
"containerEnv": {
39+
"VITE_GRAFANA_URL": "http://grafana:3000",
40+
"VITE_GRAFANA_CHANGE_ORIGIN": "false"
41+
},
3942
"postCreateCommand": "npm install commitizen -g",
4043
"customizations": {
4144
"vscode": {
@@ -45,4 +48,4 @@
4548
}
4649
},
4750
"remoteUser": "root"
48-
}
51+
}

config-ui/vite.config.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { defineConfig } from 'vite';
2121
import react from '@vitejs/plugin-react';
2222
import svgr from 'vite-plugin-svgr';
2323

24+
// Allow Grafana access from the dev server when using Dev Container
25+
const grafanaOrigin = process.env.VITE_GRAFANA_URL || 'http://localhost:3002';
26+
const grafanaChangeOrigin = envBool('VITE_GRAFANA_CHANGE_ORIGIN', true);
27+
2428
// https://vitejs.dev/config/
2529
export default defineConfig({
2630
plugins: [react(), svgr()],
@@ -36,8 +40,9 @@ export default defineConfig({
3640
rewrite: (path) => path.replace(/^\/api\//, ''),
3741
},
3842
'/grafana': {
39-
target: 'http://localhost:3002/',
40-
changeOrigin: true,
43+
target: grafanaOrigin,
44+
changeOrigin: grafanaChangeOrigin,
45+
ws: true // Proxying websockets to allow features like query auto-complete
4146
},
4247
},
4348
},
@@ -48,3 +53,9 @@ export default defineConfig({
4853
},
4954
},
5055
});
56+
57+
function envBool(name: string, defaultValue = false): boolean {
58+
const v = process.env[name];
59+
if (v == null) return defaultValue;
60+
return /^(1|true|yes|on)$/i.test(v);
61+
}

0 commit comments

Comments
 (0)