version: '3.8'

services:
  nationvalues:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=file:./data/production.db
      - PUBLIC_APP_NAME=NationValues
      - RATE_LIMIT_VOTES_PER_DAY=10
      - RATE_LIMIT_COMMENTS_PER_DAY=20
      - RATE_LIMIT_VALUES_PER_DAY=10
      - ENABLE_GEOLOCATION=true
      - ENABLE_FINGERPRINTING=true
      - ENABLE_RATE_LIMITING=true
      - GEOLITE2_DB_PATH=./data/GeoLite2-Country.mmdb
      - LOG_LEVEL=info
    volumes:
      # Persist SQLite database
      - ./data:/app/data
      # Optional: Mount GeoLite2 database from host
      # - ./data/GeoLite2-Country.mmdb:/app/data/GeoLite2-Country.mmdb:ro
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # Optional: Nginx reverse proxy for production
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      # - ./ssl:/etc/nginx/ssl:ro  # Mount SSL certificates
    depends_on:
      - nationvalues
    restart: unless-stopped
    profiles:
      - with-nginx

volumes:
  data:
    driver: local 