# Nginx Config Template for Docker
# Uses environment variables from .env files
# Variables: DEPLOYMENT_NAME, MANAGED_DOMAIN, SOLEPRINT_DOMAIN, MANAGED_*

# =============================================================================
# MANAGED DOMAIN
# =============================================================================
# Completely defined by the parent deployment (e.g., core_room)
# Soleprint doesn't know or care about the managed app's structure
server {
    listen 80;
    server_name ${MANAGED_DOMAIN};

    # All location blocks defined in MANAGED_LOCATIONS env var
    ${MANAGED_LOCATIONS}
}

# =============================================================================
# SOLEPRINT - Main Service + Ecosystem
# =============================================================================
server {
    listen 80;
    server_name ${SOLEPRINT_DOMAIN};

    # Artery - API Gateway
    location /artery/ {
        proxy_pass http://${DEPLOYMENT_NAME}_artery:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Album - Media Service
    location /album/ {
        proxy_pass http://${DEPLOYMENT_NAME}_album:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Ward - Admin Interface
    location /ward/ {
        proxy_pass http://${DEPLOYMENT_NAME}_ward:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Soleprint - Main Service (default)
    location / {
        proxy_pass http://${DEPLOYMENT_NAME}_soleprint:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
