diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a9e43722772..94b84f20f66 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,6 @@ * limitations under the License. * */ - { "name": "Go", "dockerComposeFile": "docker-compose.yml", @@ -36,6 +35,10 @@ 4000, 8080 ], + "containerEnv": { + "VITE_GRAFANA_URL": "http://grafana:3000", + "VITE_GRAFANA_CHANGE_ORIGIN": "false" + }, "postCreateCommand": "npm install commitizen -g", "customizations": { "vscode": { @@ -45,4 +48,4 @@ } }, "remoteUser": "root" -} +} \ No newline at end of file diff --git a/config-ui/package.json b/config-ui/package.json index c10c1c9d9ec..cd00e507e87 100644 --- a/config-ui/package.json +++ b/config-ui/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "packageManager": "yarn@3.4.1", "scripts": { - "start": "vite", + "start": "vite --host --strictPort", "build": "vite build", "preview": "vite preview", "lint": "tsc && eslint . --fix", diff --git a/config-ui/vite.config.ts b/config-ui/vite.config.ts index b9def37db0c..99f4de9ed9f 100644 --- a/config-ui/vite.config.ts +++ b/config-ui/vite.config.ts @@ -21,6 +21,10 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import svgr from 'vite-plugin-svgr'; +// Allow Grafana access from the dev server when using dev container +const grafanaOrigin = process.env.VITE_GRAFANA_URL || 'http://localhost:3002'; +const grafanaChangeOrigin = envBool('VITE_GRAFANA_CHANGE_ORIGIN', true); + // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), svgr()], @@ -36,8 +40,9 @@ export default defineConfig({ rewrite: (path) => path.replace(/^\/api\//, ''), }, '/grafana': { - target: 'http://localhost:3002/', - changeOrigin: true, + target: grafanaOrigin, + changeOrigin: grafanaChangeOrigin, + ws: true // Proxying websockets to allow features like query auto-complete }, }, }, @@ -48,3 +53,9 @@ export default defineConfig({ }, }, }); + +function envBool(name: string, defaultValue = false): boolean { + const v = process.env[name]; + if (v == null) return defaultValue; + return /^(1|true|yes|on)$/i.test(v); +}