added script to run with .env

This commit is contained in:
2026-06-04 18:45:27 +02:00
parent 1af79461b1
commit 7045e3dfd1
4 changed files with 23 additions and 0 deletions
+3
View File
@@ -13,6 +13,9 @@ FROM nginx:alpine AS runner
WORKDIR /usr/share/nginx/html WORKDIR /usr/share/nginx/html
COPY --from=builder /app/dist . COPY --from=builder /app/dist .
COPY docker-entrypoint.d/10-runtime-env.sh /docker-entrypoint.d/10-runtime-env.sh
RUN chmod +x /docker-entrypoint.d/10-runtime-env.sh
COPY nginx.conf /etc/nginx/templates/default.conf.template COPY nginx.conf /etc/nginx/templates/default.conf.template
EXPOSE 80 EXPOSE 80
@@ -0,0 +1,10 @@
#!/bin/sh
set -eu
VITE_BACKEND_URL_VALUE="${VITE_BACKEND_URL:-/backend}"
cat > /usr/share/nginx/html/env.js <<EOF
window.__ENV = {
VITE_BACKEND_URL: "${VITE_BACKEND_URL_VALUE}"
};
EOF
+1
View File
@@ -8,6 +8,7 @@
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
<script src="/env.js"></script>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
</body> </body>
</html> </html>
+9
View File
@@ -1,4 +1,13 @@
type WindowWithEnv = Window & {
__ENV?: {
VITE_BACKEND_URL?: string;
};
};
const runtimeEnv = (globalThis as unknown as WindowWithEnv).__ENV;
export const API_BASE = export const API_BASE =
runtimeEnv?.VITE_BACKEND_URL ||
(import.meta as any).env?.VITE_BACKEND_URL || (import.meta as any).env?.VITE_BACKEND_URL ||
import.meta.env.VITE_BACKEND_URL || import.meta.env.VITE_BACKEND_URL ||
"http://localhost:8004"; "http://localhost:8004";