refactor(server): extract /channels route group (Refs #3502)#3528
Conversation
Move the 11 inline `/channels*` handlers out of server.ts into a new
dedicated `src/server/routes/channelRoutes.ts`, mounted via
`apiRouter.use('/channels', channelRoutes)`. Handler bodies are moved
verbatim (paths made relative to the `/channels` prefix); auth/validation
middleware (optionalAuth / requireAuth / requirePermission) is preserved
identically and in order, so the final API paths are byte-identical.
Handlers moved (11): GET /channels/all, GET /channels, GET
/channels/:id/export, PUT /channels/:id, DELETE /channels/:id, POST
/channels/:slotId/import, POST /channels/reorder, POST
/channels/decode-url, POST /channels/encode-url, POST
/channels/import-config, POST /channels/refresh.
The three channel-move helpers (detectChannelMoves,
snapshotChannelsBeforeChange, migrateMessagesIfChannelsMoved) were
server.ts-local and used only by these handlers, so they moved into the
new module too. Their now-orphaned server.ts imports (migrateAutomationChannels,
modemPresetChannelName) are removed.
Inline `apiRouter.{get,post,put,delete,patch}` handler count in server.ts:
89 -> 78.
Adds routes/channelRoutes.test.ts (31 cases) covering CRUD validation +
happy paths, import/export validation, URL encode/decode, reorder
permutation checks, and MeshCore branch guards.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(server): extract /channels route groupTasks:
SummaryThis is a well-executed verbatim extraction. Handler bodies are unchanged, paths are correctly made relative to the A few items worth noting: Issues Found1. Stale import in
|
Summary
Final clean-extraction batch for tech-debt #3502: moves the
/channelsroute group (and only that group) out of theserver.tsmonolith into a dedicatedsrc/server/routes/channelRoutes.ts. This is the last cleanly-extractable group — large and mixed-concern (CRUD + import/export + URL encode/decode + MeshCore registry calls), which is why it gets its own PR.Behaviour-preserving: handler bodies moved verbatim, paths made relative to the
/channelsprefix, mounted viaapiRouter.use('/channels', channelRoutes)so final API paths are byte-identical. Auth/validation middleware preserved identically and in order.Handlers moved (11)
/channels/all/channels/channels/:id/export/channels/:id/channels/:id/channels/:slotId/import/channels/reorder/channels/decode-url/channels/encode-url/channels/import-config/channels/refreshBefore / after inline handler count
Inline
apiRouter.{get,post,put,delete,patch}(...)handlers inserver.ts: 89 → 78 (exactly 11 removed).Helper handling
The three channel-move helpers —
detectChannelMoves,snapshotChannelsBeforeChange,migrateMessagesIfChannelsMoved— were server.ts-local and verified to be used only by the/channelshandlers, so they moved into the new module. Their now-orphaned server.ts imports (migrateAutomationChannels,modemPresetChannelName) were removed; all other shared imports remain in use elsewhere.Tests
Adds
routes/channelRoutes.test.ts(31 cases): CRUD + key/ID validation, channel export normalization + filename header, import/export validation, URL encode/decode happy + error paths, reorder permutation checks + identity short-circuit, and MeshCore-branch guards (16-byte secret validation, unregistered-manager 503).Verification
success: true,numFailedTests: 0,numFailedTestSuites: 0(7362 total tests).npm run typecheck: clean.eslinton changed files: 0 errors (only verbatimno-explicit-anycarryover warnings).What remains inline = the B4-coupled core
The remaining heavy-coupling groups are still inline in
server.tsand are exactly the Phase-3 groups the issue flagged as needing themeshtasticManager.ts(section B4) split before they can be cleanly extracted:/config(15)/nodes(17)/admin(17)/settings(17, would extend existingsettingsRoutes.ts)/messages(6, would extendmessageRoutes.ts)These call deep into
meshtasticManagerinternals, so they should follow the B4 manager split rather than a plain cut-paste.Refs #3502
🤖 Generated with Claude Code