deploy: route frontend and core through one origin
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
backend_base_url=${BACKEND_BASE_URL-/api}
|
||||
if ! /usr/local/bin/validate-backend-url "$backend_base_url"; then
|
||||
echo "Invalid BACKEND_BASE_URL: use empty/root, /api, or a valid http(s) base without credentials, query, or fragment" >&2
|
||||
THT_FRONTEND_API_UPSTREAM=${THT_FRONTEND_API_UPSTREAM:-http://core:8787}
|
||||
THT_FRONTEND_API_UPSTREAM=${THT_FRONTEND_API_UPSTREAM%/}
|
||||
case "$THT_FRONTEND_API_UPSTREAM" in
|
||||
http://*|https://*) ;;
|
||||
*)
|
||||
echo "Invalid THT_FRONTEND_API_UPSTREAM: use an internal http(s) upstream" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
export THT_FRONTEND_API_UPSTREAM
|
||||
|
||||
if ! envsubst '${THT_FRONTEND_API_UPSTREAM}' \
|
||||
< /etc/nginx/templates/default.conf.template \
|
||||
> /etc/nginx/conf.d/default.conf; then
|
||||
echo "Unable to render nginx API upstream configuration" >&2
|
||||
exit 2
|
||||
fi
|
||||
runtime_config=$(jq -cn --arg backend_base_url "$backend_base_url" \
|
||||
'{backendBaseUrl: $backend_base_url}')
|
||||
printf 'window.__THOTHII_CONFIG__ = %s;\n' "$runtime_config" \
|
||||
> /usr/share/nginx/html/config.js
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
exec "$@"
|
||||
|
||||
Reference in New Issue
Block a user