added script to run with .env
This commit is contained in:
@@ -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
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|||||||
Reference in New Issue
Block a user