Repository navigation
Conversation
added 2 commits
November 3, 2026 00:12
…ace-customers#1121)
…tomers#1121) - 301 carries cache.control (max-age=604800), as the Angular redirect does today via addCacheControl - failed lookups (non-OK, errors, timeouts) are warned at most once per minute, with the count - missing or invalid timeoutMs falls back to 1000 ms instead of aborting every lookup - a body left unread by a failed JSON parse or abort is cancelled
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
Part of https://github.com/dataquest-dev/dspace-customers/issues/1121.
/handle/<prefix>/<suffix>is rendered by Angular SSR only to send a 301 to the object's page (0.4–1 s of Node CPU per hit on dspace.jcu.cz). On 2026-11-02 a scraper sent tens of thousands of these and saturated Node; the backend was not the bottleneck.HEADon a handle URL also returns 200 instead of 301 (ngApprenders onlyGET; upstream DSpace#4042).Change
An Express route in
server.ts, before the catch-all render, forGET/HEAD/handle/<prefix>/<suffix>[/](src/backend/handle-redirect.ts):/api/discover/search/objects?query=handle:"<handle>", 1 s timeout, no cookies or auth forwarded, redirects not followed);301with a relativeLocation, likeDsoRedirectService:/communities/<uuid>,/collections/<uuid>,/items/<uuid>, or/entities/<type>/<uuid>when the item has a visibledspace.entity.type;ui.nameSpaceis prefixed and the query is dropped, as today;pid/findbecausepid/findreturns only a REST URL and cannot tell/itemsfrom/entities;Authorization), no or ambiguous results, other types, deeper paths, errors and timeouts fall through to Angular unchanged;cache.control(max-age=604800), which the Angular redirect gets today throughaddCacheControl(every handle contains a dot);console.warnat most once per minute, with the count, so a broken setup is visible; a missing or invalidtimeoutMsfalls back to 1000 ms;ssr.handleRedirect.enabled(defaulttrue,DSPACE_SSR_HANDLEREDIRECT_ENABLED=falsedisables),ssr.handleRedirect.timeoutMs(1000).Tests
npm run test:handle-redirect: 50 passed (item, community, collection, entity type, trailing slash, query, HEAD, namespace, unknown/ambiguous, timeout/error fall-through, logged-in, switch off, Cache-Control, throttled warnings, invalidtimeoutMs, body release).npm run test:ssr-cache-stats: 7 passed.npx tsc --project tsconfig.server.json --noEmit: passed.npm run lint: passed (existing warnings);eslint src/backend/handle-redirect.ts: clean.npm run build:prod: passed on the first commit; not rerun after the review fixes (server-only change,tscpasses).Not done: a load test, and a check against the live backend for restricted or withdrawn items (they fall through to Angular by design).
Review
Scrutiny reviews (Claude Fable, Mistral): no correctness or security findings in the redirect itself. Fixed in the second commit: missing Cache-Control on the 301, silent failures, invalid
timeoutMs, body not released after a failed parse.Alternative
The same redirect can be answered by nginx with
pid/find(no FE image needed); that variant is described in https://github.com/dataquest-dev/dspace-customers/issues/1121.