fix the prefix in UI #1

Open
opened 2026-03-24 21:31:50 +00:00 by despiegk · 4 comments
Owner

use skill /hero_web_prefix

make sure we use proper prefixes in admin interface e in ...._ui

use skill /hero_web_prefix make sure we use proper prefixes in admin interface e in ...._ui
Author
Owner
Add `X-Forwarded-Prefix` support to the `my_compute_holo_ui` admin dashboard so it works correctly when served behind a reverse proxy at a sub-path (e.g., `/my_compute_holo_ui`).

Implementation Spec for Issue #1 — Fix the prefix in UI

Objective

Add X-Forwarded-Prefix support to the my_compute_holo_ui admin dashboard so it works correctly when served behind a reverse proxy at a sub-path (e.g., /my_compute_holo_ui).

Requirements

  • Axum middleware reads X-Forwarded-Prefix header and makes it available to all handlers
  • Every Askama template receives a base_path variable and prefixes all absolute URLs
  • JavaScript (dashboard.js) uses BASE_PATH for all fetch/location/WebSocket URLs
  • When header is absent, base_path is "" (unchanged behavior)

Files to Modify

  • crates/my_compute_holo_ui/src/server.rs — Add BasePath middleware, update all template structs and handlers
  • crates/my_compute_holo_ui/templates/base.html — Prefix 11 static asset references, inject BASE_PATH JS variable
  • crates/my_compute_holo_ui/templates/partials/navbar.html — Prefix 3 navbar links
  • crates/my_compute_holo_ui/templates/partials/sidebar.html — Prefix 5 sidebar links
  • crates/my_compute_holo_ui/templates/index.html — Prefix ~8 inline JS hrefs
  • crates/my_compute_holo_ui/templates/nodes.html — Prefix 1 inline JS href
  • crates/my_compute_holo_ui/static/js/dashboard.js — Prefix 9 hardcoded URL patterns

Implementation Plan (10 Steps)

Step 1: Add BasePath middleware to server.rs

  • Create BasePath(String) struct
  • Create base_path_middleware function that reads X-Forwarded-Prefix header
  • Register middleware on router
  • Dependencies: none

Step 2: Add base_path field to all Askama template structs

  • Update IndexTemplate, NodesTemplate, VmsTemplate, AdminTemplate, SettingsTemplate
  • Dependencies: Step 1

Step 3: Extract and pass base_path in all page handlers

  • Each handler extracts Extension(BasePath(base_path)) and passes to template
  • Dependencies: Step 2

Step 4: Update base.html template

  • Inject <script>var BASE_PATH = "{{ base_path }}";</script> in head
  • Prefix all 11 static asset href/src attributes
  • Dependencies: Step 2

Step 5: Update partials/navbar.html

  • Prefix 3 navigation links
  • Dependencies: Step 2

Step 6: Update partials/sidebar.html

  • Prefix 5 navigation links
  • Dependencies: Step 2

Step 7: Update index.html inline JS hrefs

  • Replace ~8 hardcoded hrefs with BASE_PATH-prefixed versions
  • Dependencies: Step 4

Step 8: Update nodes.html inline JS hrefs

  • Replace 1 hardcoded href
  • Dependencies: Step 4

Step 9: Update dashboard.js

  • Add var BASE_PATH = window.BASE_PATH || ""; fallback
  • Prefix all 9 URL patterns (rpc, explorer/rpc, settings, openrpc.json, version, WebSocket)
  • Dependencies: Step 4

Step 10: Add unit test for middleware

  • Test trailing slash trimming logic
  • Dependencies: Step 1

Acceptance Criteria

  • Direct access (no proxy) works identically to current version
  • Behind proxy with X-Forwarded-Prefix, all static assets load
  • Navigation links work with prefix
  • JSON-RPC calls use prefixed URLs
  • WebSocket console works with prefix
  • cargo build compiles without warnings
  • Existing tests pass

--- ## Implementation Spec for Issue #1 — Fix the prefix in UI ### Objective Add `X-Forwarded-Prefix` support to the `my_compute_holo_ui` admin dashboard so it works correctly when served behind a reverse proxy at a sub-path (e.g., `/my_compute_holo_ui`). ### Requirements - Axum middleware reads `X-Forwarded-Prefix` header and makes it available to all handlers - Every Askama template receives a `base_path` variable and prefixes all absolute URLs - JavaScript (`dashboard.js`) uses `BASE_PATH` for all fetch/location/WebSocket URLs - When header is absent, `base_path` is `""` (unchanged behavior) ### Files to Modify - `crates/my_compute_holo_ui/src/server.rs` — Add BasePath middleware, update all template structs and handlers - `crates/my_compute_holo_ui/templates/base.html` — Prefix 11 static asset references, inject BASE_PATH JS variable - `crates/my_compute_holo_ui/templates/partials/navbar.html` — Prefix 3 navbar links - `crates/my_compute_holo_ui/templates/partials/sidebar.html` — Prefix 5 sidebar links - `crates/my_compute_holo_ui/templates/index.html` — Prefix ~8 inline JS hrefs - `crates/my_compute_holo_ui/templates/nodes.html` — Prefix 1 inline JS href - `crates/my_compute_holo_ui/static/js/dashboard.js` — Prefix 9 hardcoded URL patterns ### Implementation Plan (10 Steps) #### Step 1: Add BasePath middleware to server.rs - Create `BasePath(String)` struct - Create `base_path_middleware` function that reads `X-Forwarded-Prefix` header - Register middleware on router - Dependencies: none #### Step 2: Add `base_path` field to all Askama template structs - Update IndexTemplate, NodesTemplate, VmsTemplate, AdminTemplate, SettingsTemplate - Dependencies: Step 1 #### Step 3: Extract and pass `base_path` in all page handlers - Each handler extracts `Extension(BasePath(base_path))` and passes to template - Dependencies: Step 2 #### Step 4: Update `base.html` template - Inject `<script>var BASE_PATH = "{{ base_path }}";</script>` in head - Prefix all 11 static asset href/src attributes - Dependencies: Step 2 #### Step 5: Update `partials/navbar.html` - Prefix 3 navigation links - Dependencies: Step 2 #### Step 6: Update `partials/sidebar.html` - Prefix 5 navigation links - Dependencies: Step 2 #### Step 7: Update `index.html` inline JS hrefs - Replace ~8 hardcoded hrefs with BASE_PATH-prefixed versions - Dependencies: Step 4 #### Step 8: Update `nodes.html` inline JS hrefs - Replace 1 hardcoded href - Dependencies: Step 4 #### Step 9: Update `dashboard.js` - Add `var BASE_PATH = window.BASE_PATH || "";` fallback - Prefix all 9 URL patterns (rpc, explorer/rpc, settings, openrpc.json, version, WebSocket) - Dependencies: Step 4 #### Step 10: Add unit test for middleware - Test trailing slash trimming logic - Dependencies: Step 1 ### Acceptance Criteria - [ ] Direct access (no proxy) works identically to current version - [ ] Behind proxy with `X-Forwarded-Prefix`, all static assets load - [ ] Navigation links work with prefix - [ ] JSON-RPC calls use prefixed URLs - [ ] WebSocket console works with prefix - [ ] `cargo build` compiles without warnings - [ ] Existing tests pass ---
Author
Owner

Test Results

  • Status: FAIL - Compilation error
  • Crate: my_compute_holo_server
  • Total errors: 18

Error Summary

  1. E0432 - Unresolved import hero_proc_sdk (1 occurrence)

    • File: crates/my_compute_holo_server/src/cloud/server/../hero_proc_jobs.rs:9
    • The crate hero_proc_sdk is either not linked or not available at the expected path.
  2. E0282 - Type annotations needed (17 occurrences)

    • All in crates/my_compute_holo_server/src/cloud/server/../hero_proc_jobs.rs and rpc.rs
    • These are cascading failures caused by the unresolved hero_proc_sdk import. Once the import is fixed, most or all of these should resolve.

Root Cause

The primary issue is that hero_proc_sdk cannot be resolved. This is likely because:

  • The dependency is missing from Cargo.toml, or
  • The feature gate enabling it is not active, or
  • The hero_proc_sdk crate API changed in a way that breaks the import path.

Next Steps

  • Verify hero_proc_sdk is listed as a dependency in crates/my_compute_holo_server/Cargo.toml
  • Check if the correct branch/revision of hero_proc is referenced
  • After fixing the import, re-run cargo test
## Test Results - **Status: FAIL** - Compilation error - **Crate:** `my_compute_holo_server` - **Total errors:** 18 ### Error Summary 1. **`E0432` - Unresolved import `hero_proc_sdk`** (1 occurrence) - File: `crates/my_compute_holo_server/src/cloud/server/../hero_proc_jobs.rs:9` - The crate `hero_proc_sdk` is either not linked or not available at the expected path. 2. **`E0282` - Type annotations needed** (17 occurrences) - All in `crates/my_compute_holo_server/src/cloud/server/../hero_proc_jobs.rs` and `rpc.rs` - These are cascading failures caused by the unresolved `hero_proc_sdk` import. Once the import is fixed, most or all of these should resolve. ### Root Cause The primary issue is that `hero_proc_sdk` cannot be resolved. This is likely because: - The dependency is missing from `Cargo.toml`, or - The feature gate enabling it is not active, or - The `hero_proc_sdk` crate API changed in a way that breaks the import path. ### Next Steps - Verify `hero_proc_sdk` is listed as a dependency in `crates/my_compute_holo_server/Cargo.toml` - Check if the correct branch/revision of `hero_proc` is referenced - After fixing the import, re-run `cargo test`
Author
Owner

Implementation Summary

Changes Made

crates/my_compute_holo_ui/src/server.rs

  • Added BasePath struct and base_path_middleware that reads X-Forwarded-Prefix header
  • Registered middleware on the Axum router
  • Added base_path: String field to all 5 Askama template structs
  • Updated all 5 page handlers to extract BasePath from extensions and pass to templates
  • Added test_base_path_trimming unit test

crates/my_compute_holo_ui/templates/base.html

  • Injected <script>var BASE_PATH = "{{ base_path }}";</script> in <head>
  • Prefixed all 6 static asset references (favicon, 4 CSS, 5 JS) with {{ base_path }}

crates/my_compute_holo_ui/templates/partials/navbar.html

  • Prefixed 3 navigation links (/, /settings, /openrpc.json) with {{ base_path }}

crates/my_compute_holo_ui/templates/partials/sidebar.html

  • Prefixed 5 sidebar links (/, /nodes, /vms, /admin, /settings) with {{ base_path }}

crates/my_compute_holo_ui/templates/index.html

  • Prefixed 3 HTML template hrefs with {{ base_path }}
  • Prefixed 5 inline JS-generated hrefs with BASE_PATH variable

crates/my_compute_holo_ui/templates/nodes.html

  • Prefixed 1 inline JS-generated href with BASE_PATH variable

crates/my_compute_holo_ui/static/js/dashboard.js

  • Added var BASE_PATH = window.BASE_PATH || ""; fallback
  • Prefixed 9 hardcoded URL patterns: /rpc, /explorer/rpc, /settings, /openrpc.json, /explorer-openrpc.json, /version, /console/, and 2 inline href strings

Test Results

  • cargo test -p my_compute_holo_ui: 6 passed, 0 failed
  • Note: my_compute_holo_server has a pre-existing compilation issue (missing hero_proc_sdk) unrelated to these changes

Notes

  • When no X-Forwarded-Prefix header is present, base_path is empty string — behavior is identical to before
  • External CDN URLs (bootstrap-icons) are not prefixed
  • Relative font URLs in CSS continue to work correctly regardless of prefix
## Implementation Summary ### Changes Made **`crates/my_compute_holo_ui/src/server.rs`** - Added `BasePath` struct and `base_path_middleware` that reads `X-Forwarded-Prefix` header - Registered middleware on the Axum router - Added `base_path: String` field to all 5 Askama template structs - Updated all 5 page handlers to extract `BasePath` from extensions and pass to templates - Added `test_base_path_trimming` unit test **`crates/my_compute_holo_ui/templates/base.html`** - Injected `<script>var BASE_PATH = "{{ base_path }}";</script>` in `<head>` - Prefixed all 6 static asset references (favicon, 4 CSS, 5 JS) with `{{ base_path }}` **`crates/my_compute_holo_ui/templates/partials/navbar.html`** - Prefixed 3 navigation links (`/`, `/settings`, `/openrpc.json`) with `{{ base_path }}` **`crates/my_compute_holo_ui/templates/partials/sidebar.html`** - Prefixed 5 sidebar links (`/`, `/nodes`, `/vms`, `/admin`, `/settings`) with `{{ base_path }}` **`crates/my_compute_holo_ui/templates/index.html`** - Prefixed 3 HTML template hrefs with `{{ base_path }}` - Prefixed 5 inline JS-generated hrefs with `BASE_PATH` variable **`crates/my_compute_holo_ui/templates/nodes.html`** - Prefixed 1 inline JS-generated href with `BASE_PATH` variable **`crates/my_compute_holo_ui/static/js/dashboard.js`** - Added `var BASE_PATH = window.BASE_PATH || "";` fallback - Prefixed 9 hardcoded URL patterns: `/rpc`, `/explorer/rpc`, `/settings`, `/openrpc.json`, `/explorer-openrpc.json`, `/version`, `/console/`, and 2 inline href strings ### Test Results - `cargo test -p my_compute_holo_ui`: **6 passed, 0 failed** - Note: `my_compute_holo_server` has a pre-existing compilation issue (missing `hero_proc_sdk`) unrelated to these changes ### Notes - When no `X-Forwarded-Prefix` header is present, `base_path` is empty string — behavior is identical to before - External CDN URLs (bootstrap-icons) are not prefixed - Relative font URLs in CSS continue to work correctly regardless of prefix
Author
Owner

Implementation committed: 5f8120a

Browse: 5f8120a

Implementation committed: `5f8120a` Browse: https://forge.ourworld.tf/geomind_code/my_compute_holo/commit/5f8120a
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_code/my_compute_holo#1
No description provided.