Skip to content

Deduplicate the authorization-server route helpers#474

Merged
alistair3149 merged 1 commit into
masterfrom
router-dry-followup
Jul 23, 2026
Merged

Deduplicate the authorization-server route helpers#474
alistair3149 merged 1 commit into
masterfrom
router-dry-followup

Conversation

@alistair3149

Copy link
Copy Markdown
Member

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 inline const one = … in both readAuthorizeQuery and the callback route).
  • sendAuthError(res, status, reason) — one helper replaces the eight identical res.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/register route 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

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
alistair3149 marked this pull request as ready for review July 23, 2026 13:48
@alistair3149
alistair3149 merged commit bbd8802 into master Jul 23, 2026
1 check passed
@alistair3149
alistair3149 deleted the router-dry-followup branch July 23, 2026 13:48
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