DaCrow13 commited on
Commit
d11db8f
·
1 Parent(s): 385d201

fix(docker): configure Grafana for hf.space domain to fix asset loading

Browse files
docker/nginx.conf CHANGED
@@ -79,8 +79,8 @@ http {
79
  }
80
 
81
  location /grafana/ {
82
- # Strip the path. Grafana will be configured with serve_from_sub_path=false
83
- proxy_pass http://127.0.0.1:3000/;
84
  proxy_set_header Host $host;
85
  proxy_set_header X-Real-IP $remote_addr;
86
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
79
  }
80
 
81
  location /grafana/ {
82
+ # Do NOT strip the path. explicit serve_from_sub_path=true in Grafana needs the prefix.
83
+ proxy_pass http://127.0.0.1:3000;
84
  proxy_set_header Host $host;
85
  proxy_set_header X-Real-IP $remote_addr;
86
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
docker/scripts/start_space.sh CHANGED
@@ -88,8 +88,14 @@ prometheus \
88
 
89
  # Start Grafana
90
  if [ -n "$SPACE_ID" ]; then
91
- echo "$(date) - Detected HF Space environment (ID: $SPACE_ID). Configuring Grafana Root URL..."
92
- GRAFANA_ROOT_URL="https://huggingface.co/spaces/$SPACE_ID/grafana/"
 
 
 
 
 
 
93
  else
94
  echo "$(date) - No SPACE_ID found. Defaulting Grafana to localhost."
95
  GRAFANA_ROOT_URL="http://localhost:3000/grafana/"
@@ -102,7 +108,7 @@ grafana-server --homepath=/usr/share/grafana \
102
  cfg:default.paths.logs=/tmp/grafana_logs \
103
  cfg:default.paths.plugins=/usr/share/grafana/plugins \
104
  cfg:server.root_url="$GRAFANA_ROOT_URL" \
105
- cfg:server.serve_from_sub_path=false \
106
  >> /tmp/grafana.log 2>&1 &
107
 
108
  # Wait for Grafana to start
 
88
 
89
  # Start Grafana
90
  if [ -n "$SPACE_ID" ]; then
91
+ # Parse username and space name from SPACE_ID (user/space)
92
+ # This allows us to construct the .hf.space domain which avoids CORS/Asset loading issues
93
+ SPACE_AUTHOR=$(echo $SPACE_ID | cut -d'/' -f1)
94
+ SPACE_NAME=$(echo $SPACE_ID | cut -d'/' -f2)
95
+ SPACE_HOST="${SPACE_AUTHOR}-${SPACE_NAME}.hf.space"
96
+
97
+ echo "$(date) - Detected HF Space environment (ID: $SPACE_ID). Configured Host: $SPACE_HOST"
98
+ GRAFANA_ROOT_URL="https://$SPACE_HOST/grafana/"
99
  else
100
  echo "$(date) - No SPACE_ID found. Defaulting Grafana to localhost."
101
  GRAFANA_ROOT_URL="http://localhost:3000/grafana/"
 
108
  cfg:default.paths.logs=/tmp/grafana_logs \
109
  cfg:default.paths.plugins=/usr/share/grafana/plugins \
110
  cfg:server.root_url="$GRAFANA_ROOT_URL" \
111
+ cfg:server.serve_from_sub_path=true \
112
  >> /tmp/grafana.log 2>&1 &
113
 
114
  # Wait for Grafana to start