# docker-compose.dev.yml for development
# This setup runs two services:
# 1. The Eleventy dev server for live-reloading site changes.
# 2. The Express API server for the view counter.
#
# To start both, run: docker compose -f docker-compose.dev.yml up
#
# Your site will be available at http://localhost:8080
# Your API will be available at http://localhost:3000
services:
  # This service runs the Eleventy development server.
  eleventy:
    build:
      context: .
      target: development # Use the 'development' stage from the Dockerfile
    # Adding `init: true` ensures that the container's main process receives
    # signals correctly (like SIGINT/SIGTERM) when you stop the container.
    # This helps the dev server to shut down gracefully.
    init: true
    container_name: eleventy_dev
    ports:
      - "8080:8080" # Eleventy dev server port
    volumes:
      # Mount the project directory for live-reloading.
      # The anonymous volume for node_modules prevents the local one from overwriting the container's.
      - .:/app
      - /app/node_modules
    networks:
      # Both services need to be on the same network for the Eleventy dev server
      # to proxy requests to the API container using its service name ('api').
      - dev_network
    # This command runs Eleventy's dev server with file watching.
    command: npm start

  # This service runs your Express API server.
  api:
    build:
      context: .
      target: development # Use the same 'development' stage
    # Adding `init: true` is especially important for debugging. It ensures
    # the Node.js process receives shutdown signals, allowing the debugger
    # to detach cleanly.
    init: true
    container_name: api_dev
    ports:
      - "3000:3000" # Express API server port
      - "9229:9229" # Node.js debugger port
    volumes:
      - .:/app
      - /app/node_modules
    networks:
      - dev_network
    # Use Node's built-in --watch mode instead of nodemon. It can be more
    # stable inside Docker and avoids some of nodemon's complexities.
    # The --inspect flag is still used for debugging.
    command: node --watch --inspect=0.0.0.0:9229 src/server.js

networks:
  dev_network:
    driver: bridge
