# ------------------------
# Build stage
# ------------------------
FROM node:22-bullseye AS builder

ARG API_BASE_URL="https://navigolabs.com/api"

WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy source files
COPY . .

# Pass API URL to Vite
ENV VITE_API_BASE_URL=$API_BASE_URL

# Build the app
RUN npm run build


# ------------------------
# Production stage
# ------------------------
FROM node:22-alpine AS production

WORKDIR /app

# Copy build output from builder
COPY --from=builder /app/dist ./dist

# Install a lightweight static server
RUN npm install -g serve@14

# Expose port
EXPOSE 3000

# Start the app
CMD ["serve", "-s", "dist", "-l", "3000"]
