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
Open
JCU/fix(ssr): return HTTP 404 for non-existent routes behind the dev-6.pc proxy#1473Kasinhou wants to merge 1 commit into
Kasinhou wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
dspace-ui-teststests/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-testrenders the 404 page client-side while answering HTTP 200, failing the status assertion.Root cause (not a 404-component bug)
PageNotFoundComponentalready callsServerResponseService.setNotFound()andserver.tsreturns 404 correctly when SSR runs. SSR does not run for this host:server.tsbuilds the SSR engine withallowedHosts: [ new URL(ui.baseUrl).hostname ](upstream-required). SSR only renders when the requestHostmatches; any other host silently falls back toclientSideRender(), which always answers 200.ui.baseUrlis the DSpace defaulthttp://localhost:4000, but the instance is reached through nginx ondev-6.pc, sodev-6.pc∉['localhost']→ CSR fallback → 200 for every path.Proven live: spoofing
Host: localhost:4000makes 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.allowedHostsconfig list merged with theui.baseUrlhostname when constructing theCommonEngine, and listdev-6.pcfor JCU.src/config/ssr-config.interface.ts— optionalallowedHosts?: string[].server.ts—allowedHosts = unique([ baseUrl hostname, ...ssr.allowedHosts ]).config/config.yml—ssr.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.tsbuild take effect. After redeploy, SSR runs fordev-6.pcand/route-does-not-exist-ui-testreturns 404.Scope
Targets the non-existent route test only, per request. The non-existent static page test is out of scope for JCU (
jcu.jsonhashas_static_page: false).🤖 Generated with Claude Code