# ── Development Stage ──────────────────────────────────────────────────────
FROM node:20-alpine AS development

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies — use ci for reproducible installs (exact lock file versions)
RUN npm ci

# Copy source code
COPY . .

# Expose Vite dev server port
EXPOSE 5173

# Start dev server with host binding for Docker
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]


# ── Build Stage ────────────────────────────────────────────────────────────
FROM node:20-alpine AS build

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build


# ── Production Stage ───────────────────────────────────────────────────────
FROM nginx:1.31.1-alpine3.23-slim AS production

# Patch Alpine system packages (resolves openssl CVEs in base image)
RUN apk update && apk upgrade --no-cache

# Copy built files to nginx
COPY --from=build /app/dist /usr/share/nginx/html

# Copy nginx config for SPA routing
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
