version: "3.8"

# 一键起 Nginx + 3 个模拟后端 + 1 个 WebSocket 服务
# 前置：把前端 dist 拷贝到 ./html 目录

services:
  nginx:
    image: nginx:1.25-alpine
    container_name: gateway
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./conf.d:/etc/nginx/conf.d:ro
      - ./certs:/etc/letsencrypt:ro
      - ./html:/var/www/html:ro
      - ./logs:/var/log/nginx
    depends_on:
      - api1
      - api2
      - api3
      - ws1
    networks: [edge]

  # ----- 模拟 3 个后端：用 hashicorp/http-echo 起一个返回 JSON 的 mock -----
  api1:
    image: hashicorp/http-echo:latest
    command: ["-listen=:3000", "-text={\"server\":\"api1\",\"data\":\"hello\"}"]
    networks: [edge]

  api2:
    image: hashicorp/http-echo:latest
    command: ["-listen=:3000", "-text={\"server\":\"api2\",\"data\":\"hello\"}"]
    networks: [edge]

  api3:
    image: hashicorp/http-echo:latest
    command: ["-listen=:3000", "-text={\"server\":\"api3\",\"data\":\"hello\"}"]
    networks: [edge]

  api4:
    image: hashicorp/http-echo:latest
    command: ["-listen=:3000", "-text={\"server\":\"backup\",\"data\":\"hello\"}"]
    networks: [edge]

  # ----- WebSocket 用一个简单 echo（生产换成你自己的服务）-----
  ws1:
    image: solsson/websocat
    command: ["-s", "0.0.0.0:4000"]
    networks: [edge]

  ws2:
    image: solsson/websocat
    command: ["-s", "0.0.0.0:4000"]
    networks: [edge]

networks:
  edge:
    driver: bridge
