#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -euo pipefail

# Wait for the upstream API service (Python core.api) to bind 127.0.0.1:5002
# before starting nginx, so nginx never serves a 502 for the API/auth/socket
# paths during boot. A boot-time 502 can be cached by an upstream cache layer
# (HA's own PWA service worker, a Cloudflare edge worker, etc.), leaving the
# UI in a stuck blank state until the cache is purged.
bashio::log.info "Waiting for upstream API on 127.0.0.1:5002..."
bashio::net.wait_for 5002 127.0.0.1 900

bashio::log.info "Starting NGinx..."
exec nginx
