refactor(server): extract backup + notification route groups (Refs #3502)#3523
Conversation
) Phase 2 Batch 2 of the server.ts route extraction (#3502). Moves four cohesive inline route groups out of the server.ts composition root into dedicated routes/ modules, behaviour-preserving (handler bodies moved verbatim, auth/validation middleware unchanged). Extracted: - /backup/* -> backupRoutes.ts (backupRouter) - /system/backup/* -> backupRoutes.ts (systemBackupRouter) - /push/* -> notificationRoutes.ts (pushRouter) - /apprise/* -> notificationRoutes.ts (appriseRouter) Notification helpers (getUserNotificationPreferencesAsync, saveUserNotificationPreferencesAsync, applyNodeNamePrefixAsync) were already importable from utils/notificationFiltering.js, so no helper had to move; the test/Apprise handlers keep using the meshtasticManager default-export singleton exactly as before. Orphaned server.ts imports (systemBackupService + the three notification helpers) removed. server.ts: 154 -> 130 inline apiRouter handlers (-24); ~10,476 -> ~9,449 LOC. Adds backupRoutes.test.ts and notificationRoutes.test.ts (39 new tests). Full Vitest suite green (7261 tests, 0 failures); tsc clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(server): extract backup + notification route groupsTasks:
SummaryThis is a clean, well-structured refactor that correctly extracts 24 route handlers out of Findings
|
… & status route groups (Refs #3502) (#3525) 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>
…3524) (#3529) Harden the system-backup download handler (carried verbatim from server.ts in #3523, now isolated and easy to fix): - Replace the synchronous fs.existsSync (which blocked the event loop in the request path) with an async fsp.access check via a static fs/promises import. - Guard both the archiver 'error' handler and the catch block with res.headersSent — the archive can error / finalize() can throw after archive.pipe(res) has begun streaming, which previously threw 'Cannot set headers after they are sent'. When already streaming, terminate via res.end(). Tests: add a 404 case (missing backup → async access rejects) and a happy-path streaming case (real temp dir → real archiver → 200 tar.gz + audit log). Closes #3524. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Phase 2 Batch 2 of the
server.tsinline-route extraction tracked in #3502 (continuing #3509 Phase 1 and #3519 Phase 2 Batch 1). Moves four cohesive inline route groups out of theserver.tscomposition root into dedicatedroutes/modules, behaviour-preserving — handler bodies moved verbatim, auth/validation middleware (requirePermission,requireAuth,optionalAuth,requireAdmin) unchanged.Refs #3502 (this is an increment, not a close).
Route groups extracted
/backup/*(5)routes/backupRoutes.tsbackupRouter/backup/system/backup/*(5)routes/backupRoutes.tssystemBackupRouter/system/backup/push/*(8)routes/notificationRoutes.tspushRouter/push/apprise/*(6)routes/notificationRoutes.tsappriseRouter/apprise24 inline handlers moved total.
Notes on coupling
getUserNotificationPreferencesAsync,saveUserNotificationPreferencesAsync,applyNodeNamePrefixAsync) were already exported fromutils/notificationFiltering.js, so no server-local helper needed to move.meshtasticManagerdefault-export singleton exactly as before (imported into the route module).server.tsimports:systemBackupServiceand the three notification helpers.Inline-handler count in server.ts
apiRouter.{get,post,put,delete,patch}(...)handlers (~10,476 LOC)What remains
Per #3502's inventory, still inline (future batches):
/config(15),/channels(11),/nodes(17),/admin(17),/settingsremaining (17),/system(8),/telemetry(7),/connection(5),/device(5),/scripts(5), plus assorted smaller groups.Tests
backupRoutes.test.tsandnotificationRoutes.test.ts(39 tests covering happy paths, validation/400s, path-traversal guards, audit logging, and Apprise scheme allow-listing).success: true).tsc --noEmitclean. New route files lint clean (backupRoutes.ts0 warnings;notificationRoutes.tsonly pre-existingno-explicit-anywarnings carried over verbatim from the original handlers).🤖 Generated with Claude Code