# Build Stage
FROM node:20-alpine AS builder

WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Production Stage
FROM node:20-alpine

WORKDIR /app

# Copy built assets
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./

# Install serve globally
RUN npm install -g serve

# Expose port
EXPOSE 3000

# Environment
ENV NODE_ENV=production
ENV PORT=3000
ENV HOST=0.0.0.0

# Start server - MUST bind to 0.0.0.0 for Docker
CMD ["serve", "dist", "-l", "3000", "--config", "{\"public\":\"dist\",\"directoryListing\":false}"]
