#!/bin/bash
# Expose HAProxy ports to host
set -euo pipefail

echo "🌐 Exposing HAProxy ports..."

# Expose HAProxy main (port 80) → localhost:8080
incus config device remove veza-haproxy http-proxy 2>/dev/null || true
incus config device add veza-haproxy http-proxy proxy \
    listen=tcp:0.0.0.0:8080 \
    connect=tcp:10.10.10.6:80 2>/dev/null && \
    echo "✅ HAProxy exposed on http://localhost:8080" || \
    echo "⚠️  Proxy already exists"

# Expose HAProxy stats (port 8404) → localhost:8404
incus config device remove veza-haproxy stats-proxy 2>/dev/null || true
incus config device add veza-haproxy stats-proxy proxy \
    listen=tcp:0.0.0.0:8404 \
    connect=tcp:10.10.10.6:8404 2>/dev/null && \
    echo "✅ HAProxy Stats exposed on http://localhost:8404/stats" || \
    echo "⚠️  Stats proxy already exists"

echo ""
echo "Access URLs:"
echo "  🌐 Application:     http://localhost:8080"
echo "  📊 HAProxy Stats:   http://localhost:8404/stats"
