# 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 - serve will bind to 0.0.0.0 automatically with these
ENV NODE_ENV=production
ENV PORT=3000
ENV HOST=0.0.0.0
ENV SERVE_LISTEN=0.0.0.0:3000

# Start server - simple command, env vars handle binding
CMD ["serve", "dist"]
