refactor(server): extract mesh-request, telemetry, connection, device & status route groups (Refs #3502)#3525
Conversation
… & status route groups (Refs #3502) Continues the server.ts route-extraction effort (#3502) by moving 21 inline apiRouter handlers into five cohesive routes/ modules, matching the established Router-per-module pattern (PRs #3519, #3523). Extracted (behaviour-preserving, middleware order identical): - meshRequestRoutes.ts — /traceroute, /position/request, /nodeinfo/request, /neighborinfo/request, /telemetry/request (carries the neighbor-info rate-limit map) - telemetryRoutes.ts — /direct-neighbors and the /telemetry/* query endpoints (:nodeId, /rates, /smarthops, /linkquality, DELETE :nodeId/:type, /available/nodes) - connectionRoutes.ts — /connection (GET, /disconnect, /reconnect, /info, /configure) - deviceStatusRoutes.ts — /device/tx-status, /device/security-keys - statusRoutes.ts — /virtual-node/status, /automation/airtime-status Mounted connectionRoutes at /connection; the mixed-prefix routers mount at / to keep full paths verbatim. server.ts inline handler count drops from 130 to 109. All handler dependencies were already imported from utils/ modules, so no server.ts-local helpers needed exporting. Added a *.test.ts per new module (33 new tests). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(server) — extract mesh-request, telemetry, connection, device & status route groupsTasks:
Overall this is a clean, well-structured refactor that follows the established pattern. The handler logic is faithfully extracted with auth/middleware preserved in the correct order. Tests are appropriately scoped and cover the key validation branches. Here are a few observations: Findings1. The // connectionRoutes.ts:33
if (!req.session.userId) {Every other extracted route uses 2. const neighborInfoRequestTimestamps = new Map<number, number>();This is a module-level singleton that survives across 3. const ipRegex = /^(?:(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}...)|[\w.-]+)(?::\d{1,5})?$/;The 4. const nodes = await filterNodesByChannelPermission(allNodes, (req as any).user);All other callers in the same file use 5. const managers = sourceManagerRegistry.getAllManagers() as any[];
6. Tests — missing coverage for
Summary
This is a mechanical extraction PR and achieves its goal cleanly. The observations above are minor and mostly pre-existing — none are blockers. |
Summary
Continues the
server.tsroute-extraction effort (Refs #3502) by moving 21 inlineapiRouterhandlers out ofsrc/server/server.tsinto five cohesiveroutes/*Routes.tsmodules, matching the established Router-per-module pattern from PRs #3519 and #3523. This is an increment, not a close.Route groups extracted
meshRequestRoutes.tsPOST /traceroute,/position/request,/nodeinfo/request,/neighborinfo/request,/telemetry/request(carries the neighbor-info rate-limit map + constant)telemetryRoutes.tsGET /direct-neighbors,/telemetry/:nodeId,/telemetry/:nodeId/rates,/telemetry/:nodeId/smarthops,/telemetry/:nodeId/linkquality,DELETE /telemetry/:nodeId/:telemetryType,GET /telemetry/available/nodesconnectionRoutes.tsGET /connection,POST /connection/disconnect,/reconnect,GET /connection/info,POST /connection/configuredeviceStatusRoutes.tsGET /device/tx-status,/device/security-keysstatusRoutes.tsGET /virtual-node/status,/automation/airtime-statusAll handler bodies moved verbatim; auth/validation middleware (
requirePermission,requireAuth,optionalAuth,requireAdmin) preserved identically and in the same order.connectionRoutesmounts at/connection; the mixed-prefix routers mount at/(likelinkPreviewRoutes/scriptContentRoutes) so full paths stay verbatim.Inline handler count in server.ts
All extracted handlers depended only on already-imported helpers from
utils/(parseDestinationNum,resolveSourceManager,nodeEnhancer,sourceManagerRegistry,getEnvironmentConfig,PortNum) — noserver.ts-local helpers needed exporting/moving. TheresolveSourceConnectionConfighelper (used by/polland/config) was intentionally left inserver.ts.Tests
Added a
*.test.tsper new module (33 new tests) modeled onannounceRoutes.test.ts/backupRoutes.test.ts, covering key validation and happy paths (incl. neighbor-info eligibility + rate-limiting, connection IP validation, telemetry node classification).Verification
success: true,numFailedTests: 0,numFailedTestSuites: 0(2268 suites, 6714 passed / 580 skipped).npm run typecheck: clean.no-explicit-anywarnings on verbatim-movedas anycasts, matching existing route modules).What remains (for future increments)
Heavier-coupling groups still inline in
server.ts:/config(~15),/channels(~11),/nodes(~17),/admin(~17), the remaining/settings/*(~17),/system+ version/upgrade, and/scripts.🤖 Generated with Claude Code