Inject API origin bootstrap and update docs
This commit is contained in:
41
start.sh
41
start.sh
@@ -756,6 +756,15 @@ webauthn:
|
||||
rpid: "$RP_ID"
|
||||
rporigins:
|
||||
- "$PHOTOS_URL"
|
||||
EOF_CFG
|
||||
|
||||
if [ "$USE_SUBDOMAIN_ROUTING" = true ]; then
|
||||
cat >> "$MUSEUM_CONFIG" <<EOF_CFG
|
||||
- "$ACCOUNTS_URL"
|
||||
EOF_CFG
|
||||
fi
|
||||
|
||||
cat >> "$MUSEUM_CONFIG" <<EOF_CFG
|
||||
|
||||
key:
|
||||
encryption: $MASTER_KEY
|
||||
@@ -854,6 +863,33 @@ rewrite_frontend_reference() {
|
||||
fi
|
||||
}
|
||||
|
||||
inject_api_origin_script() {
|
||||
local file="$1"
|
||||
python3 - "$file" "$API_ORIGIN" <<'PY'
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
origin = sys.argv[2]
|
||||
marker = 'data-ente-config="api-origin"'
|
||||
try:
|
||||
data = path.read_text()
|
||||
except (FileNotFoundError, UnicodeDecodeError):
|
||||
sys.exit(2)
|
||||
|
||||
if marker in data or '<head>' not in data:
|
||||
sys.exit(2)
|
||||
|
||||
snippet = f'<script {marker}>(function(){{try{{var o={origin!r};window.__ENTE_CONFIG__=Object.assign(window.__ENTE_CONFIG__||{{}},{{apiOrigin:o}});if(window.localStorage){{window.localStorage.setItem("apiOrigin",o);}}}}catch(e){{}}}})();</script>'
|
||||
data = data.replace('<head>', '<head>' + snippet, 1)
|
||||
path.write_text(data)
|
||||
PY
|
||||
local status=$?
|
||||
if [ "$status" -eq 0 ]; then
|
||||
log INFO "Injected API origin snippet into ${file#$WEB_RUNTIME_DIR/}"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ -d "$WEB_RUNTIME_DIR" ]; then
|
||||
log INFO "Rewriting frontend endpoints for local deployment"
|
||||
FRONTEND_REPLACEMENTS=(
|
||||
@@ -874,6 +910,11 @@ if [ -d "$WEB_RUNTIME_DIR" ]; then
|
||||
rewrite_frontend_reference "$search" "$replace"
|
||||
done
|
||||
IFS="$OLD_IFS"
|
||||
|
||||
log INFO "Injecting API origin bootstrap script for frontends"
|
||||
while IFS= read -r -d '' html_file; do
|
||||
inject_api_origin_script "$html_file" || true
|
||||
done < <(find "$WEB_RUNTIME_DIR" -type f -name "*.html" -print0)
|
||||
fi
|
||||
|
||||
log INFO "Ensuring CLI configuration"
|
||||
|
||||
Reference in New Issue
Block a user