Deduplicate the authorization-server route helpers#474
Merged
Conversation
Fold the micro-duplication left after the router extraction, all local to
router.ts:
- firstScalar() replaces the two copies of the query-param scalar coercion (in
readAuthorizeQuery and the callback route).
- sendAuthError(res, status, reason) replaces the eight identical
res.status(...).type('html').send(renderAuthErrorPage(...)) chains.
- proxyEnabledOr404(res) folds the five identical "proxy must be enabled" 404
guards; the register route keeps its own guard (it also checks the redirect
policy). The empty-body 404 is preserved.
Behaviour-preserving; the end-to-end proxy suite covers every route. router.ts
391 -> 371 lines.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
alistair3149
marked this pull request as ready for review
July 23, 2026 13:48
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.
Small, behaviour-preserving cleanup — the micro-DRY deliberately deferred from #472, now that the AS routes are all co-located in
router.ts.What
firstScalar()— one helper replaces the two copies of the query-param first-scalar coercion (was an inlineconst one = …in bothreadAuthorizeQueryand the callback route).sendAuthError(res, status, reason)— one helper replaces the eight identicalres.status(…).type('html').send(renderAuthErrorPage({ reason }))chains.proxyEnabledOr404(res)— folds the five identical "proxy must be enabled → empty-body 404" guards into one helper (const pc = proxyEnabledOr404(res); if (!pc) return;, TS-narrowed, no assertions). The/mcp/registerroute keeps its own guard since it also checks the redirect policy. The empty-body 404 behaviour is preserved.router.ts: 391 → 371 lines.Testing
Behaviour-preserving, so the existing suite is the safety net: full gate green (
fmt:check,lint,tsc, whole suite), and the 23-case end-to-end proxy suite — which drives every one of these routes and error paths — stays green. Pure-internal refactor, no CHANGELOG/README per AGENTS.md.🤖 Generated with Claude Code