Skip to content

JCU/fix(ssr): return HTTP 404 for non-existent routes behind the dev-6.pc proxy - #1473

Open
Kasinhou wants to merge 1 commit into
customer/jcufrom
jcu/fix-ssr-404-allowed-hosts
Open

JCU/fix(ssr): return HTTP 404 for non-existent routes behind the dev-6.pc proxy#1473
Kasinhou wants to merge 1 commit into
customer/jcufrom
jcu/fix-ssr-404-allowed-hosts

Conversation

@Kasinhou

Copy link
Copy Markdown

Problem

dspace-ui-tests tests/tests/notFoundPage.spec.ts (UNIVERSAL-016) fails for JCU on the non-existent route scenario across chromium/firefox/webkit. verifyNotFoundPage() asserts the HTTP status is 404, but on http://dev-6.pc:8593 /route-does-not-exist-ui-test renders the 404 page client-side while answering HTTP 200, failing the status assertion.

Root cause (not a 404-component bug)

PageNotFoundComponent already calls ServerResponseService.setNotFound() and server.ts returns 404 correctly when SSR runs. SSR does not run for this host:

  • server.ts builds the SSR engine with allowedHosts: [ new URL(ui.baseUrl).hostname ] (upstream-required). SSR only renders when the request Host matches; any other host silently falls back to clientSideRender(), which always answers 200.
  • The deployed ui.baseUrl is the DSpace default http://localhost:4000, but the instance is reached through nginx on dev-6.pc, so dev-6.pc['localhost'] → CSR fallback → 200 for every path.

Proven live: spoofing Host: localhost:4000 makes SSR return 404 for the same URL, confirming the FE code is correct and only host gating is at fault.

Fix

Add an optional ssr.allowedHosts config list merged with the ui.baseUrl hostname when constructing the CommonEngine, and list dev-6.pc for JCU.

  • src/config/ssr-config.interface.ts — optional allowedHosts?: string[].
  • server.tsallowedHosts = unique([ baseUrl hostname, ...ssr.allowedHosts ]).
  • config/config.ymlssr.allowedHosts: [dev-6.pc].
  • config/config.example.yml — documented, commented-out example.

Matched by hostname only (port ignored). Harmless in production, where the public hostname already matches ui.baseUrl.

Deploy note

Requires a frontend redeploy on dev-6.pc so the new config.yml + server.ts build take effect. After redeploy, SSR runs for dev-6.pc and /route-does-not-exist-ui-test returns 404.

Scope

Targets the non-existent route test only, per request. The non-existent static page test is out of scope for JCU (jcu.json has has_static_page: false).

🤖 Generated with Claude Code

…return 404 behind a proxy

Angular's SSR engine only renders a request when its Host header matches
`ui.baseUrl`'s hostname; any other host silently falls back to CSR, which
always answers HTTP 200, so "not found" pages can never return a 404.

The JCU test instance is served behind nginx on dev-6.pc while the deployed
ui.baseUrl stays http://localhost:4000, so SSR was disabled for that host and
`/route-does-not-exist-ui-test` answered 200 instead of 404 (dspace-ui-tests
notFoundPage.spec.ts / UNIVERSAL-016).

Add an optional `ssr.allowedHosts` config list that is merged with the
baseUrl hostname when constructing the CommonEngine, and list dev-6.pc for the
JCU deployment. Matched by hostname only (port ignored); harmless in
production, where the public hostname already matches ui.baseUrl.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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