Skip to content

Commit

Permalink
[Upd #151] Revert to 86002d3 to have runtime environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Jan 25, 2024
1 parent f05533d commit 097306b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ RUN npm run build
FROM nginx
COPY --from=build /usr/src/app/dist /usr/share/nginx/html/
RUN chmod a+r -R /usr/share/nginx/html

COPY deploy/.docker/config.js.template /etc/nginx/config.js.template
COPY deploy/.docker/error.html /usr/share/nginx/html/error.html
COPY deploy/.docker/nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
COPY deploy/.docker/docker-entrypoint.sh /
RUN chmod a+x /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]
5 changes: 5 additions & 0 deletions deploy/.docker/config.js.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Dynamic configuration
window.__config__ = {
API_URL:'${API_URL}',
ADMIN_REGISTRATION_ONLY:'${ADMIN_REGISTRATION_ONLY}'
}
6 changes: 6 additions & 0 deletions deploy/.docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -eu

envsubst '${API_URL} ${ADMIN_REGISTRATION_ONLY}' < /etc/nginx/config.js.template > /usr/share/nginx/html/config.js

exec "$@"
4 changes: 2 additions & 2 deletions deploy/no-proxy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
fta-fmea:
image: ghcr.io/kbss-cvut/fta-fmea-ui:latest
environment:
VITE_API_URL: ${VITE_API_URL:-http://localhost:9999/}
VITE_ADMIN_REGISTRATION_ONLY: ${VITE_ADMIN_REGISTRATION_ONLY:-false}
API_URL: ${VITE_API_URL:-http://localhost:9999/}
ADMIN_REGISTRATION_ONLY: ${VITE_ADMIN_REGISTRATION_ONLY:-false}
ports:
- "8080:80"
depends_on:
Expand Down
6 changes: 6 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Window {
__config__: {
API_URL: string;
ADMIN_REGISTRATION_ONLY: string;
}
}
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Runtime environment variables -->
<script src="/config.js"></script>
<title>FTA/FMEA Analysis</title>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion src/services/utils/axiosUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {appHistory} from "@components/routes/AppRoutes";
import {ROUTES} from "@utils/constants";

const axiosClient = axios.create({
baseURL: import.meta.env.VITE_API_URL
baseURL: (window as any).__config__.API_URL
});

axiosClient.interceptors.response.use(
Expand Down

0 comments on commit 097306b

Please sign in to comment.