#!/bin/bash

set -eo pipefail

# Replace variables in the config file

replace_vars() {
  OUTPUT=$(echo $1 | sed -e 's/.source//');
  SOURCE=$1

  eval "cat <<EOF
  $(<$SOURCE)
EOF
  " > $OUTPUT
}

if [ -e "/src/config/runtime.json.source" ]
then
  replace_vars "/src/config/runtime.json.source"
fi

echo "Configuration settings"
cat "/src/config/runtime.json"

echo "starting nodejs service..."
nodejs .
