#!/bin/sh

ROOT_DIR=/app

# Replace env vars in JavaScript files
echo "Replacing env constants in JS"
for file in $ROOT_DIR/assets/app.*.js* $ROOT_DIR/js/app.*.js* $ROOT_DIR/assets/QSpace-*.js* $ROOT_DIR/index.html $ROOT_DIR/precache-manifest*.js $ROOT_DIR/assets/index*.js* $ROOT_DIR/assets/*.js*;
do
  echo "Processing $file ...";

  sed -i 's|VITE_API_URI_CONFIG|'${VITE_API_URI_CONFIG}'|g' $file
  sed -i 's|VITE_API_REPORT_URL|'${VITE_API_REPORT_URL}'|g' $file
  sed -i 's|VITE_MANUAL_URL|'${VITE_MANUAL_URL}'|g' $file
  sed -i 's|VITE_URL_SSO|'${VITE_URL_SSO}'|g' $file
  sed -i 's|VITE_URL_LANDING|'${VITE_URL_LANDING}'|g' $file

done

echo "Starting Nginx"
nginx -g 'daemon off;'

