#!/usr/bin/env bash set -euo pipefail # Run the app locally without Docker. # Loads environment variables from .env and the Eloverblik refresh token from .token. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$ROOT_DIR" load_env_file() { local file="$1" [[ -f "$file" ]] || return 0 while IFS= read -r line || [[ -n "$line" ]]; do # Trim CR from CRLF files. line="${line%$'\r'}" # Skip blank lines and full-line comments. [[ -z "${line//[[:space:]]/}" || "$line" =~ ^[[:space:]]*# ]] && continue # Allow lines prefixed with "export ". line="${line#export }" local key="${line%%=*}" local value="${line#*=}" # Trim whitespace around the key only; preserve value contents (e.g. JDBC_URL query strings). key="$(printf '%s' "$key" | xargs)" if [[ ! "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ || "$line" != *=* ]]; then echo "Skipping invalid env line in $file: $line" >&2 continue fi # Remove one matching pair of surrounding quotes, if present. if [[ "$value" =~ ^\".*\"$ || "$value" =~ ^\'.*\'$ ]]; then value="${value:1:${#value}-2}" fi export "$key=$value" done < "$file" } load_env_file ".env" if [[ -f ".token" && -z "${ELOVERBLIK_TOKEN:-}" ]]; then ELOVERBLIK_TOKEN="$(tr -d '\r\n' < .token)" export ELOVERBLIK_TOKEN fi : "${PORT:=3000}" export PORT # Energi Data Service currently serves only the leaf certificate. Allow the JVM # to fetch missing intermediate CA certificates from the certificate AIA URL. export JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS:-} -Dcom.sun.security.enableAIAcaIssuers=true" echo "Starting elprice locally on port $PORT (no Docker)..." # `clj` requires rlwrap for REPL command editing. Fall back to `clojure` # when rlwrap is not installed so the app can still start. if command -v rlwrap >/dev/null 2>&1; then exec clj -M:dev -e "(dev-prep!) (go)" -r else echo "rlwrap not found; using clojure instead of clj (REPL editing disabled)." >&2 exec clojure -M:dev -e "(dev-prep!) (go)" -r fi