# Small base image with Node and apk to install curl
FROM node:18-alpine

# Install curl for container health checks
RUN apk add --no-cache curl

# Create app dir
WORKDIR /app

# Install dependencies first (better layer caching)
COPY package.json package-lock.json* ./
RUN npm install --omit=dev

# Copy source
COPY server.js ./

# App listens on port 80
EXPOSE 80

# Health check using curl to hit /healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3   CMD curl -fsS http://localhost/healthcheck || exit 1

# Start the app
CMD ["npm","start"]
