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/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 5cc69156..e4756567 100644
--- a/frontend/vite.config.js
+++ b/frontend/vite.config.js
@@ -1,5 +1,5 @@
-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({
@@ -7,14 +7,7 @@ export default defineConfig({
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: ''
- })
- }
-})
+});