#!/bin/sh
set -e

if [ "$IS_PRODUCT" = "true" ]; then
    cp /etc/nginx/conf.d/frontend.product.conf /etc/nginx/conf.d/frontend.conf
    echo "nginx: production mode (static files from /var/www/html)"
    i=0
    while [ ! -f /var/www/html/index.html ]; do
        i=$((i + 1))
        if [ "$i" -gt 120 ]; then
            echo "nginx: WARNING: /var/www/html/index.html not found after 240s"
            break
        fi
        sleep 2
    done
else
    cp /etc/nginx/conf.d/frontend.dev.conf /etc/nginx/conf.d/frontend.conf
    echo "nginx: development mode (proxy to frontend:5173)"
fi

exec nginx -g 'daemon off;'
