#!/bin/sh
set -eu

backend_host="${BACKEND_HOST:-chore-app-backend}"
ssl_enabled="$(printf '%s' "${FRONTEND_SSL_ENABLED:-true}" | tr '[:upper:]' '[:lower:]')"

template_file="/etc/nginx/nginx.http.conf.template"

case "$ssl_enabled" in
  1|true|yes|on)
    template_file="/etc/nginx/nginx.conf.template"
    ;;
esac

sed "s|\$BACKEND_HOST|${backend_host}|g" "$template_file" > /etc/nginx/nginx.conf

nginx -t
exec nginx -g 'daemon off;'
