fleetnow/docker-entrypoint.d/30-fleetnow-env.sh
david kiania 7138571c0e feat(staging): runtime API-base injection via /env.js
Parameterize the previously hardcoded API_BASE so a staging build can point at
the staging API without forking the code:

  - env.js.template + /docker-entrypoint.d/30-fleetnow-env.sh render ${API_BASE}
    into /env.js on container start (envsubst ships with the nginx image)
  - index.html loads /env.js and uses window.FLEETNOW_API_BASE, falling back to
    the prod API (https://fleetapi.rahamafresh.com) when unset — so prod/main is
    unchanged; staging sets API_BASE=https://fleetapi.fivetitude.com
  - nginx: serve /env.js with no-store

Enables the fleetnow.fivetitude.com staging app (Coolify, staging branch).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 14:14:10 +03:00

17 lines
672 B
Bash

#!/bin/sh
# Render the runtime API base into /env.js before nginx starts.
# The official nginx image runs every executable /docker-entrypoint.d/*.sh at
# startup, so this fires on each container boot — letting one image serve staging
# (API_BASE=https://fleetapi.fivetitude.com) and prod (…rahamafresh.com) from the
# same build. Only ${API_BASE} is substituted; index.html falls back to the prod
# API if it's empty.
set -e
: "${API_BASE:=}"
TEMPLATE=/usr/share/nginx/html/env.js.template
OUT=/usr/share/nginx/html/env.js
if [ -f "$TEMPLATE" ]; then
envsubst '${API_BASE}' < "$TEMPLATE" > "$OUT"
echo "fleetnow: rendered /env.js with API_BASE='${API_BASE}'"
fi