feat: add HERO_PROXY_DEFAULT_SERVICE fallback for SPA routing #2

Merged
mik-tf merged 11 commits from development_default_service into development 2026-03-05 15:14:53 +00:00
Owner

When set, paths without a service prefix (e.g. /login) are forwarded to the named default service socket.

Closes #1

When set, paths without a service prefix (e.g. /login) are forwarded to the named default service socket. Closes #1
When set, paths without a service prefix (e.g. /login) are forwarded
to the named default service socket, keeping the original path intact.

This enables SPA routing where hero_os_http serves as the default
frontend without requiring the /hero_os_http/ prefix in URLs.

Closes #1
When a URL path like /login doesn't match any service socket,
the proxy now falls back to the default service instead of
returning 502 Bad Gateway.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Previously, when a path like /hero_books/ didn't match any socket,
the proxy fell back to the default service (hero_os_http), showing
the Hero OS SPA instead of a 404. Now only truly unprefixed paths
like /login or /desktop use the default service fallback. Explicit
service prefixes that don't match return 404.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous commit restricted default service to only unprefixed paths,
but extract_prefix("/login") returns Some(("login", "/")) — so paths
like /login, /desktop were getting 404 instead of routing to hero_os_http.

Restore original behavior: any path without a matching socket falls
back to the default service (when configured).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Binary names don't always match URL path prefixes:
  /hero_books/ → hero_books_server.sock (not hero_books.sock)
  /hero_embedder/ → hero_embedder_ui.sock
  /hero_inspector/ → hero_inspector_http.sock

find_socket_for() tries: exact → _http → _ui → _server,
preferring HTTP-serving sockets over backends.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_server sockets are API backends (e.g. hero_books_server). Routing
/hero_books/ to the backend returns 404 — the SPA handles books UI
internally via API calls.

Only match _http and _ui sockets as direct web UI endpoints.
_server sockets → fall back to default service (SPA).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a path has no matching service socket and a default service is
configured, issue a 302 redirect to /{default_service}{path} instead
of transparently proxying.

This ensures the browser URL always starts with the service prefix
(e.g. /hero_os_http/login instead of /login), which is required for
Dioxus SPAs that use base_path routing. Without the correct URL prefix,
Dioxus base_path causes double-prefix navigation (/hero_os_http/hero_os_http).

An anti-loop guard prevents redirect when the prefix already matches
the default service name (avoids infinite redirect if socket is gone).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per Hero naming convention:
- hero_proxy_openrpc → hero_proxy_server
- hero_proxy_http → hero_proxy_ui

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mik-tf merged commit 152936728b into development 2026-03-05 15:14:53 +00:00
Sign in to join this conversation.
No reviewers
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
lhumina_code/hero_proxy!2
No description provided.