From 4b91e6dd7513030370e0c2ed66857c252a0ece42 Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 11 Jan 2026 21:11:31 -0800 Subject: [PATCH 1/2] fix: powerbi url --- frontend/Caddyfile | 8 +++++--- frontend/vite.config.js | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/frontend/Caddyfile b/frontend/Caddyfile index 9e53e22e..6db46678 100644 --- a/frontend/Caddyfile +++ b/frontend/Caddyfile @@ -14,15 +14,17 @@ } encode gzip - handle /config.js { - header Content-Type "text/javascript" + handle /env.js { + header { + Content-Type text/javascript + } respond `window.config = {"VITE_SCHEMA_BRANCH":"{$VITE_SCHEMA_BRANCH}", "VITE_POWERBI_URL":"{$VITE_POWERBI_URL}"};` } root * /app/dist encode zstd gzip file_server @spa_router { - not path /api/* /config.js + not path /api/* /env.js file { try_files {path} /index.html } diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 5cc69156..a84f61e7 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,20 +1,40 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; // https://vite.dev/config/ export default defineConfig({ - plugins: [react()], + plugins: [ + { + name: "build-html", + apply: "build", + transformIndexHtml: (html) => { + return { + html, + tags: [ + { + tag: "script", + attrs: { + src: "/env.js", + }, + injectTo: "head", + }, + ], + }; + }, + }, + react(), + ], server: { port: 3001, proxy: { - '/api': 'http://localhost:3000', + "/api": "http://localhost:3000", }, }, define: { // Define window.config for build time - will be overridden by Caddy in production - 'window.config': JSON.stringify({ - VITE_SCHEMA_BRANCH: 'main', - VITE_POWERBI_URL: '' - }) - } -}) + "window.config": JSON.stringify({ + VITE_SCHEMA_BRANCH: "main", + VITE_POWERBI_URL: "", + }), + }, +}); From 5624adf9f35fafbc3c8d5a0375368adc1dc7be5a Mon Sep 17 00:00:00 2001 From: OMPRAKASH MISHRA Date: Sun, 11 Jan 2026 21:21:16 -0800 Subject: [PATCH 2/2] fix: powerbi url setup --- frontend/env.js | 4 +--- frontend/index.html | 1 + frontend/public/env.js | 7 +++++++ frontend/vite.config.js | 29 +---------------------------- 4 files changed, 10 insertions(+), 31 deletions(-) create mode 100644 frontend/public/env.js diff --git a/frontend/env.js b/frontend/env.js index 24a2a0ac..8e7e1b57 100644 --- a/frontend/env.js +++ b/frontend/env.js @@ -1,4 +1,2 @@ - - // eslint-disable-next-line import/prefer-default-export -export const env = { ...import.meta.env, ...window.config }; \ No newline at end of file +export const env = { ...import.meta.env, ...(globalThis.window?.config ?? {}) }; diff --git a/frontend/index.html b/frontend/index.html index bd940f47..21cee1e7 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -5,6 +5,7 @@ BCGov Public Code +
diff --git a/frontend/public/env.js b/frontend/public/env.js new file mode 100644 index 00000000..b2ae7d05 --- /dev/null +++ b/frontend/public/env.js @@ -0,0 +1,7 @@ +// Runtime configuration loaded before the Vite bundle. +// In production, Caddy serves /env.js and overwrites this response. + +window.config = window.config || { + VITE_SCHEMA_BRANCH: "main", + VITE_POWERBI_URL: "", +}; diff --git a/frontend/vite.config.js b/frontend/vite.config.js index a84f61e7..e4756567 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -3,38 +3,11 @@ import react from "@vitejs/plugin-react"; // https://vite.dev/config/ export default defineConfig({ - plugins: [ - { - name: "build-html", - apply: "build", - transformIndexHtml: (html) => { - return { - html, - tags: [ - { - tag: "script", - attrs: { - src: "/env.js", - }, - injectTo: "head", - }, - ], - }; - }, - }, - react(), - ], + plugins: [react()], server: { port: 3001, proxy: { "/api": "http://localhost:3000", }, }, - define: { - // Define window.config for build time - will be overridden by Caddy in production - "window.config": JSON.stringify({ - VITE_SCHEMA_BRANCH: "main", - VITE_POWERBI_URL: "", - }), - }, });