version: "3.9"

services:
  magic-ai-server:
    build: .
    image: magic-ai-server:1.0.0
    container_name: magic-ai-server
    restart: unless-stopped
    ports:
      - "7432:7432"
    environment:
      - PORT=7432
      - MAGIC_AI_ORIGIN=${MAGIC_AI_ORIGIN:-http://localhost:8080}
      - MAGIC_AI_KEY=${MAGIC_AI_KEY:-}
      - NODE_ENV=production
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:7432/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.magicai.rule=Host(`api.yourdomain.com`)"
      - "traefik.http.routers.magicai.entrypoints=websecure"
      - "traefik.http.routers.magicai.tls.certresolver=letsencrypt"

  # Optional: Nginx reverse proxy
  # nginx:
  #   image: nginx:alpine
  #   ports:
  #     - "80:80"
  #     - "443:443"
  #   volumes:
  #     - ./nginx.conf:/etc/nginx/conf.d/default.conf
  #     - ./public:/usr/share/nginx/html
  #   depends_on:
  #     - magic-ai-server
