You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because the middleware wraps the entire router externally, any unauthenticated or un-rate-limited route (specifically /health) must be known and checked by EVERY middleware independently.
Violation of middleware single responsibility: Middleware modules designed to validate Bearer tokens or calculate IP rate limits are tightly coupled to the application's URL routing table. Adding any future public endpoint (e.g. /metrics) requires modifying all middleware files.
Inverted dispatch on 404: Unauthenticated requests to non-existent paths return 401 Unauthorized before the router ever runs, hiding 404 Not Found behind authentication.
Test Evidence (/deintrovert-tests)
In tests/handler_test.ts, middleware tests must construct full HTTP request URLs that include /health or non-health endpoints to verify bypass behavior, coupling middleware tests to specific route paths rather than testing auth or rate-limiting invariants directly.
The Deletion Test
Deleting HEALTH_PATTERN from src/middleware.ts removes path-matching complexity from middleware entirely. Middlewares become pure transforms: withAuth only inspects headers; withRateLimit only inspects IP and request timestamps.
Proposed Change
Deepen Router so that routes or route groups can declare middleware:
Alternatively, have Router match the route first, returning the handler and its associated middleware pipeline.
Benefits
Leverage: New endpoints declare their security policy in one place (at route registration) rather than requiring edits across multiple middleware files.
Locality: Routing rules and path matching concentrate entirely in src/router.ts and src/handler.ts. Middleware concentrates strictly on auth or rate limiting.
Testability: Middleware can be tested in isolation using dummy requests without needing to construct specific URL pathnames matching /health.
Candidate Summary
src/router.ts,src/middleware.ts,src/handler.tsQueueandItem Lifecyclemodule,interface,depth,seam,adapter,leverage,localityProblem & Evidence
Currently,
Routerinsrc/router.tsis a shallow module that only registers paths and methods, and executes them against a request URL.Because
Routerdoes not own middleware or route execution pipelines,src/handler.tswraps the entirerouter.handlemethod in a global chain:Because the middleware wraps the entire router externally, any unauthenticated or un-rate-limited route (specifically
/health) must be known and checked by EVERY middleware independently.In
src/middleware.ts:And in
src/handler.ts:Friction points:
withAuthandwithRateLimitindependently parse the URL and duplicate the/health{/}?pattern. In issue Health endpoint returns 401 for trailing-slash variant /health/ (public probe marked unhealthy) #67, fixing trailing slash support required editing bothsrc/middleware.tsandsrc/handler.ts./metrics) requires modifying all middleware files.Test Evidence (
/deintrovert-tests)In
tests/handler_test.ts, middleware tests must construct full HTTP request URLs that include/healthor non-health endpoints to verify bypass behavior, coupling middleware tests to specific route paths rather than testing auth or rate-limiting invariants directly.The Deletion Test
Deleting
HEALTH_PATTERNfromsrc/middleware.tsremoves path-matching complexity from middleware entirely. Middlewares become pure transforms:withAuthonly inspects headers;withRateLimitonly inspects IP and request timestamps.Proposed Change
Deepen
Routerso that routes or route groups can declare middleware:Alternatively, have
Routermatch the route first, returning the handler and its associated middleware pipeline.Benefits
src/router.tsandsrc/handler.ts. Middleware concentrates strictly on auth or rate limiting./health.