refactor(server): extract scripts, data-exchange & server-info route groups (Refs #3502)#3526
Conversation
…groups (Refs #3502) Continue the server.ts route-extraction effort (#3502) by moving the next cohesive, low-coupling batch of inline handlers into routes/ modules. Groups extracted (11 inline handlers, 109 -> 98 remaining): - scripts (7): /scripts/test, /http/test, /scripts/import, /scripts/export, /scripts/dependencies, /scripts/dependencies/install, DELETE /scripts/:filename -> new scriptRoutes.ts. The 6 server.ts-local script helpers (getScriptsDirectory, resolveScriptPath, sanitizeMetadataValue, parseScriptMetadata, getLanguageFromExtension, scriptsEndpoint) moved into the module. getScriptsDirectory and the public scriptsEndpoint are exported; server.ts re-imports them for the dev-startup log and the app-level /api/scripts mount (which intentionally bypasses CSRF, unchanged). - data exchange (3): /stats, /export, /import -> new dataExchangeRoutes.ts. - server info (1): /server-info -> new serverInfoRoutes.ts. All handler bodies moved verbatim; auth/validation middleware (requirePermission, requireAdmin, express.raw) and path strings unchanged, so every route resolves byte-identically under /api. Removed now-orphaned imports (scriptDependencyEnv, normalizeTriggerPatterns, safeFetch, SsrfBlockedError, getDependencyStatus, installDependencies) from server.ts. Added scriptRoutes.test.ts, dataExchangeRoutes.test.ts and serverInfoRoutes.test.ts covering validation and happy paths. Verification: full Vitest suite green (6740 passed, 0 failed, 0 failed suites), tsc clean, eslint clean on all changed files (0 new errors; server.ts error count dropped 18 -> 16). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job PR Review: refactor(server): extract scripts, data-exchange & server-info route groupsTasks:
Overall AssessmentThis is a clean, behaviour-preserving refactor that follows the pattern established by earlier batches in this series. The extraction is mechanically sound and the handler bodies are moved verbatim. The three test files provide good coverage of the validation paths. A few small observations below. Code Quality & Best Practices
Potential Bugs
Security
Performance
Test CoverageTests are well-structured and cover the key validation and happy paths. A few gaps:
Minor Nits
Summary: The refactor achieves its stated goal cleanly. All observations above are either pre-existing behaviours carried over verbatim or minor polish items. No blockers identified. |
| if (regexPattern.length > 2000) { | ||
| continue; | ||
| } | ||
| const triggerRegex = new RegExp(`^${regexPattern}$`, 'i'); |
Summary
Continues the
server.tsroute-extraction effort (Refs #3502) by moving the next cohesive, low-coupling batch of inlineapiRouter.*handlers intosrc/server/routes/*Routes.tsmodules. Behaviour-preserving: handler bodies moved verbatim, middleware and path strings unchanged.Groups extracted (11 handlers)
/scripts/test,/http/test,/scripts/import,/scripts/export,/scripts/dependencies,/scripts/dependencies/install,DELETE /scripts/:filename(7)scriptRoutes.ts/stats,/export,/import(3)dataExchangeRoutes.ts/server-info(1)serverInfoRoutes.tsThe 6
server.ts-local script helpers (getScriptsDirectory,resolveScriptPath,sanitizeMetadataValue,parseScriptMetadata,getLanguageFromExtension,scriptsEndpoint) moved intoscriptRoutes.ts.getScriptsDirectoryand the publicscriptsEndpointare exported soserver.tscan keep the dev-startup log and the app-level/api/scriptsmount (which intentionally bypasses CSRF — unchanged). The__dirname-relative dev scripts-dir path was adjusted (../../→../../../) to resolve to the same project root from the deeper module location.All three new routers are mounted at
apiRouter.use('/', ...)(verbatim-path style) so every route resolves byte-identically under/api. Removed now-orphaned imports fromserver.ts(scriptDependencyEnv,normalizeTriggerPatterns,safeFetch,SsrfBlockedError,getDependencyStatus,installDependencies).Inline handler count
What remains
Heavier-coupled Phase-3 groups still inline:
/config(15, config marshalling registry),/channels(11, channel-move helpers),/nodes(17,getEffectivePosition+ node enrichment),/admin(17, session-passkey/admin-command),/settings/*(extendsettingsRoutes.ts),/system+/version/check(upgrade/Docker/version helpers). Also/debug/ip(couples toapp/envand is dev-only) and/messages/send+/poll+/config(deep manager/resolveSourceConnectionConfigcoupling) were left for a later batch.Tests
Added
scriptRoutes.test.ts,dataExchangeRoutes.test.ts,serverInfoRoutes.test.tscovering validation and happy paths.Verification
tsc --noEmit: cleaneslinton changed files: 0 errors (only pre-existingno-explicit-anycarryover warnings);server.tserror count dropped 18 → 16🤖 Generated with Claude Code