#!/bin/sh

replace_env_var() {
  local var_name=$1
  local placeholder="%%$var_name%%"
  local value=$(eval echo \$$var_name)
  # inject value to the index.html
  sed -i "s|$placeholder|$value|g" /usr/share/pweb/index.html
}

echo "Starting Container"

replace_env_var "WS_PROTOCOL"
replace_env_var "WS_ENDPOINT"
replace_env_var "API_PROTOCOL"
replace_env_var "SERVICE_HOST"
replace_env_var "API_ENDPOINT"
replace_env_var "AMPLITUDE_SECRET"
replace_env_var "DEFAULT_LOCALE"
replace_env_var "DEFAULT_CURRENCY"

echo "Passing by launch command"
# Execute the passed command (e.g., starting Caddy)
# exec "$@"
exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
