#!/bin/sh
# The Orchard debian13 parent doesn't carry the official nginx image's
# envsubst-on-templates entrypoint, so we reimplement the one piece of it this
# image relies on: substitute nginx/templates/*.template -> conf.d/*.conf,
# then exec whatever command was actually requested (nginx, or `nginx -t` for
# `make check`).
set -eu

# https is correct in every real deployment (QA, prod); only a local compose
# fronting a plaintext apollo-mcp container needs to override it.
export MCP_UPSTREAM_SCHEME="${MCP_UPSTREAM_SCHEME:-https}"

envsubst '${AUTH0_DOMAIN} ${AUTH0_ORGANIZATION} ${MCP_UPSTREAM_HOST} ${MCP_UPSTREAM_SCHEME} ${PROXY_ORIGIN} ${APOLLO_MCP_CLIENT_ID} ${CLIENT_REDIRECT_URI} ${RESOLVER}' \
  < /etc/nginx/templates/default.conf.template \
  > /etc/nginx/conf.d/default.conf

exec "$@"
