Skip to content

Commit 4eee62d

Browse files
authored
fix: powerbi url (#562)
1 parent 421ce28 commit 4eee62d

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

frontend/Caddyfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
}
1515
encode gzip
1616

17-
handle /config.js {
18-
header Content-Type "text/javascript"
17+
handle /env.js {
18+
header {
19+
Content-Type text/javascript
20+
}
1921
respond `window.config = {"VITE_SCHEMA_BRANCH":"{$VITE_SCHEMA_BRANCH}", "VITE_POWERBI_URL":"{$VITE_POWERBI_URL}"};`
2022
}
2123
root * /app/dist
2224
encode zstd gzip
2325
file_server
2426
@spa_router {
25-
not path /api/* /config.js
27+
not path /api/* /env.js
2628
file {
2729
try_files {path} /index.html
2830
}

frontend/env.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
2-
31
// eslint-disable-next-line import/prefer-default-export
4-
export const env = { ...import.meta.env, ...window.config };
2+
export const env = { ...import.meta.env, ...(globalThis.window?.config ?? {}) };

frontend/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link rel="icon" href="/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>BCGov Public Code</title>
8+
<script src="/env.js"></script>
89
</head>
910
<body>
1011
<div id="root"></div>

frontend/public/env.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Runtime configuration loaded before the Vite bundle.
2+
// In production, Caddy serves /env.js and overwrites this response.
3+
4+
window.config = window.config || {
5+
VITE_SCHEMA_BRANCH: "main",
6+
VITE_POWERBI_URL: "",
7+
};

frontend/vite.config.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import { defineConfig } from 'vite'
2-
import react from '@vitejs/plugin-react'
1+
import { defineConfig } from "vite";
2+
import react from "@vitejs/plugin-react";
33

44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [react()],
77
server: {
88
port: 3001,
99
proxy: {
10-
'/api': 'http://localhost:3000',
10+
"/api": "http://localhost:3000",
1111
},
1212
},
13-
define: {
14-
// Define window.config for build time - will be overridden by Caddy in production
15-
'window.config': JSON.stringify({
16-
VITE_SCHEMA_BRANCH: 'main',
17-
VITE_POWERBI_URL: ''
18-
})
19-
}
20-
})
13+
});

0 commit comments

Comments
 (0)