Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions frontend/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions frontend/env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@


// eslint-disable-next-line import/prefer-default-export
export const env = { ...import.meta.env, ...window.config };
export const env = { ...import.meta.env, ...(globalThis.window?.config ?? {}) };
1 change: 1 addition & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BCGov Public Code</title>
<script src="/env.js"></script>
</head>
<body>
<div id="root"></div>
Expand Down
7 changes: 7 additions & 0 deletions frontend/public/env.js
Original file line number Diff line number Diff line change
@@ -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: "",
};
15 changes: 4 additions & 11 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
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()],
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: ''
})
}
})
});
Loading