Repository navigation
fix: dispatch SSR self-calls against the listen address - #3188
Conversation
The SSR'd auth pages built their API client from publicUrl, so every render round-tripped through the reverse proxy — a self-signed local certificate (e.g. https://hub.local) failed Node's fetch with UNABLE_TO_GET_ISSUER_CERT_LOCALLY, and the unhandled rejection from the fire-and-forget identity-provider load killed the server process. - server-core: register a default UIHttpClient (transient) whose hapic transport rewrites requests targeting publicUrl (origin + sub-path prefix, wildcard listen hosts normalized to loopback) onto the server's own listen address; baseURL stays publicUrl so rendered hrefs remain user-facing - client-web-kit: entity-collection loads no longer reject — errors are caught and emitted as 'failed', so a failed SSR fetch renders the page degraded instead of crashing the server - core-http-kit: widen ClientOptions to hapic's ClientOptionsInput, exposing the transport seam
|
Note Reviews pausedUse the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR introduces an internal HTTP client for SSR UI page self-calls, rewriting requests from the public URL to the server's internal listen address while preserving public-facing rendered hrefs. It's wired into the HTTP module's DI lifecycle, documented, and tested. Separately, entity-collection components gain a "failed" emit event triggered on load errors instead of throwing. ChangesInternal UI HTTP client for SSR self-calls
Estimated code review effort: 3 (Moderate) | ~30 minutes Entity-collection failed emit event
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant SSRPage as SSR Page Render
participant UIHttpClient as UIHttpClient
participant Rewriter as URL Rewriter
participant Server as Server (internal listen address)
SSRPage->>UIHttpClient: request(publicUrl-based path)
UIHttpClient->>Rewriter: rewrite(url)
Rewriter-->>UIHttpClient: internal-address URL
UIHttpClient->>Server: fetch(internal URL)
Server-->>UIHttpClient: response
UIHttpClient-->>SSRPage: response (rendered hrefs stay public)
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
authup
@authup/client-web
@authup/server-core
@authup/access
@authup/client-web-kit
@authup/client-web-kit-theme
@authup/client-web-nuxt
@authup/client-web-theme
@authup/core-http-kit
@authup/core-kit
@authup/core-realtime-kit
@authup/errors
@authup/i18n
@authup/kit
@authup/server-adapter-kit
@authup/server-adapter-node
@authup/server-adapter-socket-io
@authup/server-adapter-web
@authup/server-kit
@authup/server-test-kit
@authup/specs
commit: |
There was a problem hiding this comment.
Pull request overview
This PR improves SSR reliability for Authup’s UI workflow pages by ensuring server-side “self-calls” dispatch to the server’s listen address (instead of round-tripping through publicUrl and a reverse proxy), and by hardening client-web-kit SSR collection loads against unhandled promise rejections.
Changes:
- Register a default transient
UIHttpClientinserver-corethat keepsbaseURL = publicUrlfor rendered links but rewrites transport dispatch to the server listen address. - Make entity-collection
load()inclient-web-kitnever reject; emit a newfailedevent instead, preventing SSR process crashes from unhandled rejections. - Widen
core-http-kitClientOptionsto hapic’sClientOptionsInputto expose the transport seam.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core-http-kit/src/client/type.ts | Widen ClientOptions to support custom transports. |
| packages/client-web-kit/test/unit/components/workflows/login-form.spec.ts | Add regression test ensuring login form renders when IDP load fails. |
| packages/client-web-kit/src/components/utility/entity/collection/utils/component.ts | Add failed to collection component emit validators. |
| packages/client-web-kit/src/components/utility/entity/collection/types.ts | Extend collection emits typing with failed(error). |
| packages/client-web-kit/src/components/utility/entity/collection/module.ts | Catch load errors and emit failed instead of rejecting. |
| apps/server-core/test/unit/http/controllers/workflows/ui-pages-internal-client.spec.ts | Integration coverage for default internal-loopback UI client behavior. |
| apps/server-core/test/unit/adapters/http/ui/internal-http-client.spec.ts | Unit coverage for public→internal URL rewriting rules. |
| apps/server-core/test/app/factory.ts | Add config override hook to test application factory. |
| apps/server-core/src/app/modules/http/module.ts | Register transient default UI HTTP client during HTTP module setup; unregister on teardown. |
| apps/server-core/src/app/modules/http/constants.ts | Update UI HTTP client token docs to reflect production default registration. |
| apps/server-core/src/adapters/http/ui/types.ts | Add context type for internal UI HTTP client creation. |
| apps/server-core/src/adapters/http/ui/internal-http-client.ts | Implement internal UI HTTP client + URL rewriter and transport-level dispatch rewrite. |
| apps/server-core/src/adapters/http/ui/index.ts | Export internal UI HTTP client utilities. |
| apps/server-core/src/adapters/http/middleware/built-in/ui-http-client.ts | Update middleware docs to match new default client wiring. |
| .agents/testing.md | Document default UI client wiring and new internal-client integration suite. |
| .agents/architecture.md | Document SSR self-call internal client behavior and SSR crash hardening. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // a wildcard listen address (0.0.0.0 / [::]) is not reliably dialable — | ||
| // loop back explicitly | ||
| if (internalParsed.hostname === '0.0.0.0' || internalParsed.hostname === '[::]') { | ||
| internalParsed.hostname = '127.0.0.1'; | ||
| } |
There was a problem hiding this comment.
Verified against Node's WHATWG URL implementation: new URL('http://[::]:64331/').hostname returns '[::]' with brackets (the URL Standard serializes IPv6 hosts bracketed in the hostname getter), so the check does match. Legacy url.parse() is where hostname comes back bracket-less. Added an IPv6 wildcard case to the rewriter spec (e33d1df) to pin this behavior.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/server-core/src/app/modules/http/module.ts (1)
90-119: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUntested fallback branch when
server.urlis unavailable.The
new Client({ baseURL: config.publicUrl })fallback (Lines 103-114) reproduces exactly the pre-fix behavior this PR is meant to eliminate (round-tripping through the reverse proxy). None of the provided specs exercise this path (e.g. by resolvingUIHttpClientbeforeServeris registered). Worth a small unit test asserting the fallback still works whenServerisn't yet resolvable, since a regression here would silently reintroduce the original TLS/self-call bug.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/server-core/src/app/modules/http/module.ts` around lines 90 - 119, The fallback path in registerUIHttpClient is untested: when HTTPInjectionKey.Server is not yet resolvable and createInternalUIHttpClient is skipped, the code returns a Client using config.publicUrl. Add a unit test around registerUIHttpClient / UIHttpClient resolution that forces the Server lookup to be unavailable, then assert the fallback Client is created and used correctly so this branch cannot regress.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/server-core/src/app/modules/http/module.ts`:
- Around line 90-119: The fallback path in registerUIHttpClient is untested:
when HTTPInjectionKey.Server is not yet resolvable and
createInternalUIHttpClient is skipped, the code returns a Client using
config.publicUrl. Add a unit test around registerUIHttpClient / UIHttpClient
resolution that forces the Server lookup to be unavailable, then assert the
fallback Client is created and used correctly so this branch cannot regress.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e693e100-2f2c-4893-b967-1bbdec3c0964
📒 Files selected for processing (16)
.agents/architecture.md.agents/testing.mdapps/server-core/src/adapters/http/middleware/built-in/ui-http-client.tsapps/server-core/src/adapters/http/ui/index.tsapps/server-core/src/adapters/http/ui/internal-http-client.tsapps/server-core/src/adapters/http/ui/types.tsapps/server-core/src/app/modules/http/constants.tsapps/server-core/src/app/modules/http/module.tsapps/server-core/test/app/factory.tsapps/server-core/test/unit/adapters/http/ui/internal-http-client.spec.tsapps/server-core/test/unit/http/controllers/workflows/ui-pages-internal-client.spec.tspackages/client-web-kit/src/components/utility/entity/collection/module.tspackages/client-web-kit/src/components/utility/entity/collection/types.tspackages/client-web-kit/src/components/utility/entity/collection/utils/component.tspackages/client-web-kit/test/unit/components/workflows/login-form.spec.tspackages/core-http-kit/src/client/type.ts
|
@coderabbitai pause |
✅ Action performedReviews paused. |
…ract Review feedback (PR #3188): - add an IPv6 wildcard listen-address case to the rewriter spec — WHATWG URL serializes IPv6 hostnames WITH brackets, so the '[::]' check holds - reword the collection load() comment: some call sites await the promise but none reliably catch, which is the actual property the catch protects - use the isError duck guard from @authup/errors for the caught value
Integrate the merged rotation feature (#3186, squash) + SSR internal-http-client (#3188) from master. Conflict resolutions: - issuers / refresh grant / session-token repository / grant spec: take master's version (inlined row-write + review-fix hardening), dropping the now-removed persistSessionTokenRow helper - architecture.md: keep master's issuer-row wording + this branch's Session Management API section
Problem
The SSR'd auth pages (
/authorize,/register, ...) build their API client frompublicUrl, so every server-side render round-trips through the reverse proxy. With a self-signed local certificate (e.g.https://hub.local), Node's fetch fails withUNABLE_TO_GET_ISSUER_CERT_LOCALLY— and because the identity-provider list load fires as an unawaited promise, the rejection escaped the request pipeline and crashed the whole server process. The setup also silently required the container to be able to resolve and reach its own public hostname.Changes
server-core — internal loopback client for SSR self-calls
HTTPModule.setupnow registers a production default underHTTPInjectionKey.UIHttpClient(previously test-injection only; a registration made before setup still wins).createInternalUIHttpClient,adapters/http/ui/internal-http-client.ts) keepsbaseURL = publicUrl— rendered hrefs (e.g. identity-provider authorize links) derive from it and hydration does not patch attribute mismatches — while its hapicFetchTransportrewrites every request targeting the public origin + sub-path prefix onto the server's own listen address (server.url, wildcard binds normalized to loopback, resolved lazily per request).lifetime: 'transient': a fresh client per render, no shared per-user state.client-web-kit — SSR crash hardening
load()no longer rejects: errors are caught and emitted as a newfailedevent. A failed SSR fetch renders the page degraded (login form without the provider list) instead of killing the process via an unhandled rejection.core-http-kit
ClientOptionswidened fromRequestBaseOptionsto hapic'sClientOptionsInput(strictly additive), exposing thetransportseam.Tests
https://hub.local/auth), trailing slash, bare prefix, foreign origins, segment-boundary safety (/authorizevs/auth/...), wildcard-host normalization.ui-pages-internal-client.spec.ts: exercises the default client (no fake registered) against a live test server, once with default config and once withpublicUrl = 'https://hub.local/auth/'(the test factory gained a config-override hook) — loopback dispatch returns real data,getBaseURL()/getAuthorizeUri()stay public, per-request resolves yield distinct clients, and the rendered/authorizepage never leaks the listen address (and carries/auth/public/asset URLs in sub-path mode).GET /identity-providershandler → login form still renders andfailedis emitted.Full server-core suite (105 files / 1057 tests), client-web-kit and core-http-kit suites pass.
.agents/architecture.md/.agents/testing.mdupdated.Summary by CodeRabbit
New Features
Bug Fixes