From b838f1a0a90b19ed339939f32be406b1189a1ecd Mon Sep 17 00:00:00 2001 From: root <root@sae61-rott-kiefner.iutrs.unistra.fr> Date: Thu, 3 Apr 2025 16:00:30 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20:=20Mise-=C3=A0-jour=20du=20Dockerfile=20?= =?UTF-8?q?avec=20un=20vrai=20serveur=20de=20PROD.=20Ajout=20=C3=A9l=C3=A9?= =?UTF-8?q?ment=20n=C3=A9cessaire=20pour=20VITE=5FAPI=5FURL.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 22 ++++++++++++++++++---- vite.config.ts | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index b2682f1..b175c24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,33 @@ -FROM node:18-alpine AS builder - +# Use Node.js as the base image +FROM node:20 AS builder WORKDIR /app -COPY . . +# Set the ARG to accept during build time +ARG VITE_API_URL +# Set the environment variable for both build and runtime +ENV VITE_API_URL=${VITE_API_URL} + +# Copy the package.json and install dependencies +COPY package*.json ./ RUN npm install +# Copy all the files +COPY . . + +# Build the Vite project RUN npm run build +# Nginx to serve the production build FROM nginx:alpine +# Copy the built files from the builder image to Nginx COPY --from=builder /app/dist /usr/share/nginx/html - +# Expose port 80 for Nginx EXPOSE 80 +# Start Nginx server CMD ["nginx", "-g", "daemon off;"] + diff --git a/vite.config.ts b/vite.config.ts index b1ca82e..c604cca 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -8,4 +8,7 @@ export default defineConfig({ server: { port: 4200, // Remplace par le port que tu veux utiliser }, + define: { + 'process.env.VITE_API_URL': JSON.stringify(process.env.VITE_API_URL || 'http://localhost:3000'), + } }) -- GitLab