# frontend/Dockerfile.development - FIXED VERSION
FROM node:18-alpine

# Install curl for healthchecks
RUN apk add --no-cache curl

# Set working directory
WORKDIR /app

# Create non-root user for security but don't switch yet
RUN addgroup -g 1001 -S nodejs && \
    adduser -S reactjs -u 1001 -G nodejs

# Copy package files first (better caching)
COPY package*.json ./

# Install all dependencies (including dev dependencies) as root
RUN npm ci --verbose && \
    npm cache clean --force

# Copy source code
COPY . .

# Change ownership of all files to the non-root user
RUN chown -R reactjs:nodejs /app

# Now switch to non-root user
USER reactjs

# Expose port 3000 (Vite default)
EXPOSE 3000

# Add healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
  CMD curl -f http://localhost:3000/ || exit 1

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