diff --git a/docker-compose.yml b/docker-compose.yml index 37d7bfd..ec32820 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,11 +55,11 @@ services: context: . dockerfile: docker/node.Dockerfile target: frontend-runtime + args: + VITE_API_BASE_URL: ${VITE_API_BASE_URL} + VITE_API_URL: ${VITE_API_URL} + VITE_APP_ENV: ${VITE_APP_ENV:-production} container_name: vagas-frontend - env_file: - - ./frontend/.env - environment: - - VITE_API_PROXY_TARGET=http://backend:3001 ports: - "5173:80" depends_on: @@ -74,13 +74,10 @@ services: dockerfile: docker/node.Dockerfile target: front-admin-runtime args: - VITE_API_URL: https://api.candidate.app.br - VITE_APP_ENV: production + VITE_API_BASE_URL: ${VITE_API_BASE_URL} + VITE_API_URL: ${VITE_API_URL} + VITE_APP_ENV: ${VITE_APP_ENV:-production} container_name: vagas-front-admin - env_file: - - ./front_admin/.env - environment: - - VITE_API_PROXY_TARGET=http://backend:3001 ports: - "5174:80" depends_on: diff --git a/docker/node.Dockerfile b/docker/node.Dockerfile index 7ecac76..459d68c 100644 --- a/docker/node.Dockerfile +++ b/docker/node.Dockerfile @@ -24,6 +24,12 @@ CMD ["npx","tsx","src/server.ts"] FROM deps AS frontend +ARG VITE_API_BASE_URL +ARG VITE_API_URL + +ENV VITE_API_BASE_URL=$VITE_API_BASE_URL +ENV VITE_API_URL=$VITE_API_URL + COPY frontend ./frontend WORKDIR /app/frontend diff --git a/front_admin/Dockerfile b/front_admin/Dockerfile index 41ac248..f003fc2 100644 --- a/front_admin/Dockerfile +++ b/front_admin/Dockerfile @@ -12,6 +12,12 @@ COPY front_admin ./front_admin WORKDIR /app/front_admin +ARG VITE_API_URL +ARG VITE_APP_ENV=production + +ENV VITE_API_URL=$VITE_API_URL +ENV VITE_APP_ENV=$VITE_APP_ENV + RUN npm run build # ---- Runtime ---- @@ -23,4 +29,4 @@ COPY front_admin/nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 -CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 3409ab4..cf27258 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -7,7 +7,9 @@ RUN npm ci --workspace=frontend --include-workspace-root COPY frontend/ ./frontend/ WORKDIR /app/frontend ARG VITE_API_BASE_URL=http://localhost:3001 +ARG VITE_API_URL=$VITE_API_BASE_URL ENV VITE_API_BASE_URL=$VITE_API_BASE_URL +ENV VITE_API_URL=$VITE_API_URL RUN npm run build # ---- Etapa 2: serve ---- diff --git a/frontend/src/shared/lib/apiClient.ts b/frontend/src/shared/lib/apiClient.ts index 47c8ea3..d55eeb6 100644 --- a/frontend/src/shared/lib/apiClient.ts +++ b/frontend/src/shared/lib/apiClient.ts @@ -1,8 +1,13 @@ import axios from "axios"; import { parseApiError } from "./apiError"; +const API_URL = + import.meta.env.VITE_API_BASE_URL ?? + import.meta.env.VITE_API_URL ?? + "http://localhost:3001"; + export const api = axios.create({ - baseURL: import.meta.env.VITE_API_URL ?? "http://localhost:3001", + baseURL: API_URL, withCredentials: true, headers: { "Content-Type": "application/json",