From 6e55b088e9327690358a6f852a8cf95a66f790ef Mon Sep 17 00:00:00 2001 From: dvirlabs Date: Wed, 2 Jul 2025 04:40:10 +0300 Subject: [PATCH] Try fix dynamic env --- backend/__pycache__/main.cpython-313.pyc | Bin 4497 -> 4499 bytes backend/main.py | 1 - frontend/10-generate-env.sh | 4 ++ frontend/Dockerfile | 34 +++++++-------- frontend/docker-entrypoint.sh | 11 ----- frontend/src/services/api.js | 2 +- frontend/vite.config.js | 53 +++++++++++++++++++++++ 7 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 frontend/10-generate-env.sh delete mode 100644 frontend/docker-entrypoint.sh diff --git a/backend/__pycache__/main.cpython-313.pyc b/backend/__pycache__/main.cpython-313.pyc index 6f418918d7fd0604ab3dc80c53eb99ba3fc98ea1..94945ccac38ec6251befaadf2bdef6f8c9b321dc 100644 GIT binary patch delta 39 tcmbQJJXx9dGcPX}0}$j`1!b6S /usr/share/nginx/html/env.js diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 02ba70e..9f5a53f 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,29 +1,29 @@ -# Stage 1: Build -FROM node:20-alpine AS builder +# Stage 1: Build the frontend +FROM node:20 AS builder + WORKDIR /app -COPY package*.json ./ -RUN npm install --legacy-peer-deps COPY . . +RUN npm install RUN npm run build -# Stage 2: Runtime (NGINX) +# Stage 2: Serve with nginx FROM nginx:alpine -# Install dos2unix to fix Windows line endings +# Install dos2unix RUN apk add --no-cache dos2unix -# Clean default nginx html -RUN rm -rf /usr/share/nginx/html/* - -# Copy built frontend +# Copy built app COPY --from=builder /app/dist /usr/share/nginx/html -# Copy entrypoint and normalize line endings -COPY docker-entrypoint.sh /docker-entrypoint.sh -RUN dos2unix /docker-entrypoint.sh && chmod +x /docker-entrypoint.sh +# ✅ Copy env.js.template +COPY public/env.js.template /etc/env/env.js.template -# Fallback env.js (to avoid 404 before initContainer writes real one) -RUN echo "window.env = {}" > /usr/share/nginx/html/env.js +# ✅ Copy nginx config +COPY nginx.conf /etc/nginx/conf.d/default.conf -# Set entrypoint -ENTRYPOINT ["/docker-entrypoint.sh"] +# ✅ Add env generator script to nginx entrypoint hook +COPY 10-generate-env.sh /docker-entrypoint.d/10-generate-env.sh +RUN dos2unix /docker-entrypoint.d/10-generate-env.sh && chmod +x /docker-entrypoint.d/10-generate-env.sh + +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/docker-entrypoint.sh b/frontend/docker-entrypoint.sh deleted file mode 100644 index 6fab1ad..0000000 --- a/frontend/docker-entrypoint.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -set -e - -# Generate env.js at runtime from env var -cat < /usr/share/nginx/html/env.js -window.env = { - VITE_API_URL: "${VITE_API_URL}" -}; -EOF - -exec nginx -g "daemon off;" diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 309ad6a..c483f9c 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -1,4 +1,4 @@ -const API_BASE = window?.env?.VITE_API_URL || '/api'; +const API_BASE = window?.ENV?.API_BASE || ""; export async function fetchSections() { const res = await fetch(`${API_BASE}/apps`); diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 0466183..0c137ac 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,6 +1,59 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +// https://vitejs.dev/config/ export default defineConfig({ plugins: [react()], }); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// export default defineConfig({ +// plugins: [react()], +// server: { +// proxy: { +// '/apps': 'http://localhost:8000', +// '/add_app': 'http://localhost:8000', +// '/icon': 'http://localhost:8000', +// } +// } +// }); + + + + + +// import { defineConfig } from 'vite'; +// import react from '@vitejs/plugin-react'; + +// export default defineConfig({ +// plugins: [react()], +// });