Skip to content

Support single-host path/port routing, and modernize the example stack#332

Merged
LucHeart merged 6 commits into
developfrom
feature/support-path-prefixes
Jul 4, 2026
Merged

Support single-host path/port routing, and modernize the example stack#332
LucHeart merged 6 commits into
developfrom
feature/support-path-prefixes

Conversation

@LucHeart

@LucHeart LucHeart commented Jul 4, 2026

Copy link
Copy Markdown
Member

What & why

Self-hosting currently assumes a subdomain per service (api., gateway.,
frontend on the apex), which needs wildcard-capable DNS and creates a
cross-subdomain login-cookie trap. This PR lets a self-hoster run the whole stack
on one host + one port, telling services apart by path:

https://host/ -> frontend
https://host/api/... -> api (OPENSHOCK_API_PATH)
https://host/gateway/… -> gateway (OPENSHOCK_GATEWAY_PATH)

Everything is one origin, so the cookie "just works" with no apex juggling.

Backend routing (feat(routing))

  • UsePathBase on the API and gateway via config (OpenShock:Api:PathBase,
    OPENSHOCK__LCG__PUBLICPATH). Traefik routes by PathPrefix without
    stripping, so each app owns its prefix and generated URLs (OAuth redirect_uri,
    Scalar) stay correct. API host/port stay implicit (forwarded headers); only the
    gateway needs an explicit PublicPort/PublicPath since it advertises itself
    out-of-band.
  • LcgNode re-keyed on a composite public id host[:port][/path]
    (FqdnHost, added Port/PathPrefix, index lcg-online-v4v5). The id is
    backward-compatible: a default port/root gateway keeps the exact bare-host key
    it has today, so existing DeviceOnline.Gateway pointers keep resolving.
  • assignLCG v2 now returns the real Host/Port/Path; new v2
    {deviceId}/lcg
    returns the gateway's host/port/base-path so the browser builds
    the live-control URL itself. v1 endpoints stay bare-host:443 legacy.
  • Shared gateway lookup refactored to OneOf<LcgNode, OpenShockProblem>.

Example stack rework (feat(docker-compose))

  • Single-host + path knobs in .env (OPENSHOCK_HOST, OPENSHOCK_PORT,
    *_PATH); ${PORT:+…} keeps clean https://host URLs at 443.
  • Redis → DragonflyDB (--notify_keyspace_events=Ex).
  • Postgres 18 (data dir now under /var/lib/postgresql).
  • webuifrontend (PUBLIC_* env), short-link middlewares dropped.
  • README env-var docs reorganized (+ a gateway-only section and cookie-domain note).

Backward compatibility

Defaults (OPENSHOCK_PORT unset, gateway path empty) reproduce today's exact wire
behavior. Path/port gateways only work with v2-capable firmware that honors the
v2 assign Host/Port/Path; hubs on v1 firmware must stay on the default
port/root path.

Testing

  • Full solution build + svelte-check clean.
  • docker compose config validated for both default and custom-port (8080).
  • LcgAssignmentTests extended with path/port propagation + default back-compat
    cases (run these in CI — Testcontainers needs a Docker daemon).

Follow-ups (not in this PR)

  • Frontend companion changes live in the frontend repo (getGatewayWsURL,
    live-control v2 discovery); the API SDK must be regenerated against the
    deployed API to replace the temporary shim.
  • Firmware: honor the v2 assign fields for path/port gateways.

This desc was generated with an LLM.


Open in Stage

LucHeart added 2 commits July 4, 2026 17:50
Let self-hosters run the whole stack on one host under path prefixes
  (example.org/api, example.org/gateway) instead of a subdomain per service.

  - api/lcg: mount under an optional path prefix via UsePathBase
    (OpenShock:Api:PathBase, OPENSHOCK__LCG__PUBLICPATH). Traefik routes by
    PathPrefix without stripping, so generated URLs (OAuth redirect_uri, Scalar)
    keep the prefix.
  - lcg: advertise a configurable public port/path (LcgOptions.PublicPort/
    PublicPath); self-register under a composite node id host[:port][/path] that
    stays byte-identical to the old bare-host key on the default port/root path.
  - redis: re-key LcgNode on that composite id; rename Fqdn -> Host, add Port and
    PathPrefix (index lcg-online-v4 -> v5).
  - assignLCG v2 now returns the real Host/Port/Path; add a v2 {deviceId}/lcg that
    returns the gateway host/port/base-path so the browser builds the live-control
    URL itself. v1 endpoints stay bare-host:443 legacy.
  - refactor the shared gateway lookup to OneOf<LcgNode, OpenShockProblem>.
  - tests: cover path/port propagation and default backward-compatibility.
@LucHeart LucHeart requested a review from hhvrc July 4, 2026 15:55
@stage-review

stage-review Bot commented Jul 4, 2026

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1aaed76661

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread LiveControlGateway/LcgKeepAlive.cs Outdated
@LucHeart LucHeart merged commit 9c2fca3 into develop Jul 4, 2026
22 checks passed
@LucHeart LucHeart deleted the feature/support-path-prefixes branch July 4, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant