diff --git a/Dockerfile b/Dockerfile index b2682f1dc059d4f611d823d45885c1bb94e26eca..b175c24d0581c46cb663cc40762f49ffb7290f0f 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 b1ca82eb69cde41e45ee61e4d82d40fbd9274c06..c604cca9adc70f9a0710b752e01a8d616ecfea69 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'), + } })