fix(ui): rewrite image URLs to include proxy prefix when embedded #90

Merged
fatmaebrahim merged 2 commits from development_fix_image_urls_proxy into development 2026-04-20 07:10:16 +00:00
Member

Summary

Fix broken image rendering for absolute URLs (e.g. /img/foo.png) in markdown pages when hero_books is embedded inside hero_os at /hero_books/ui/. Standalone mode is unaffected.

Closes lhumina_code/hero_os#69

Changes

  • crates/hero_books_ui/src/handlers.rs — server-side: rewrite_image_urls(html, base) now prefixes absolute paths with the proxy base derived from X-Forwarded-Prefix; markdown_to_html(md, base) threads the base through; handler_page passes &base into both branches.
  • crates/hero_books_app/src/components/library.rs — client-side: new rewrite_asset_urls(html) helper reads rpc::base_path(), strips trailing /ui to derive the asset base, rewrites src="/img/...src="{asset_base}/img/.... No-op in standalone mode. Applied to markdown_to_html output.
  • crates/hero_books_app/src/components/page.rs — client-side: PageView now pipes server-rendered content_html through rewrite_asset_urls() so pre-rendered HTML also gets the prefix.

Behavioural matrix

Deployment Before After
Standalone (no proxy) /img/foo.png works /img/foo.png still works (no rewrite)
Embedded in hero_os at /hero_books/ui/ /img/foo.png 404s /img/foo.png/hero_books/img/foo.png
External (http://, https://) unchanged unchanged
data: URIs unchanged unchanged
Already-prefixed paths n/a not double-prefixed

Test Results

  • cargo build --release -p hero_books_ui -p hero_books_app — passes.
  • cargo test --release -p hero_books_ui -p hero_books_app — passes (no failures).

Caveats

  • Client-side base path is hard-coded as /hero_books/ui in crates/hero_books_app/src/app.rs:94 (when an IslandContext is present). Server-side path is dynamic via X-Forwarded-Prefix.
## Summary Fix broken image rendering for absolute URLs (e.g. `/img/foo.png`) in markdown pages when hero_books is embedded inside hero_os at `/hero_books/ui/`. Standalone mode is unaffected. ## Related Issue Closes https://forge.ourworld.tf/lhumina_code/hero_os/issues/69 ## Changes - `crates/hero_books_ui/src/handlers.rs` — server-side: `rewrite_image_urls(html, base)` now prefixes absolute paths with the proxy base derived from `X-Forwarded-Prefix`; `markdown_to_html(md, base)` threads the base through; `handler_page` passes `&base` into both branches. - `crates/hero_books_app/src/components/library.rs` — client-side: new `rewrite_asset_urls(html)` helper reads `rpc::base_path()`, strips trailing `/ui` to derive the asset base, rewrites `src="/img/...` → `src="{asset_base}/img/...`. No-op in standalone mode. Applied to `markdown_to_html` output. - `crates/hero_books_app/src/components/page.rs` — client-side: `PageView` now pipes server-rendered `content_html` through `rewrite_asset_urls()` so pre-rendered HTML also gets the prefix. ## Behavioural matrix | Deployment | Before | After | |---|---|---| | Standalone (no proxy) | `/img/foo.png` works | `/img/foo.png` still works (no rewrite) | | Embedded in hero_os at `/hero_books/ui/` | `/img/foo.png` 404s | `/img/foo.png` → `/hero_books/img/foo.png` | | External (`http://`, `https://`) | unchanged | unchanged | | `data:` URIs | unchanged | unchanged | | Already-prefixed paths | n/a | not double-prefixed | ## Test Results - `cargo build --release -p hero_books_ui -p hero_books_app` — passes. - `cargo test --release -p hero_books_ui -p hero_books_app` — passes (no failures). ## Caveats - Client-side base path is hard-coded as `/hero_books/ui` in `crates/hero_books_app/src/app.rs:94` (when an `IslandContext` is present). Server-side path is dynamic via `X-Forwarded-Prefix`.
fix(ui): rewrite image URLs to include proxy prefix when embedded
All checks were successful
Test / test (pull_request) Successful in 11m0s
Test / integration (pull_request) Successful in 4m11s
3f04319e4a
lhumina_code/hero_os#69
fix: removed base stripe line
All checks were successful
Test / test (pull_request) Successful in 10m35s
Test / integration (pull_request) Successful in 4m9s
4815c0b55f
fatmaebrahim merged commit cdfedcaf50 into development 2026-04-20 07:10:16 +00:00
fatmaebrahim deleted branch development_fix_image_urls_proxy 2026-04-20 07:10:16 +00:00
Sign in to join this conversation.
No reviewers
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
lhumina_code/hero_books!90
No description provided.