Skip to content

Refactor main.ts: extract routes and server logic into modules#84

Open
jancurn wants to merge 1 commit into
masterfrom
claude/wonderful-clarke-jp6njj
Open

Refactor main.ts: extract routes and server logic into modules#84
jancurn wants to merge 1 commit into
masterfrom
claude/wonderful-clarke-jp6njj

Conversation

@jancurn

@jancurn jancurn commented Jun 13, 2026

Copy link
Copy Markdown
Member

Split the monolithic main.ts into focused modules for better maintainability and testability. Routes are now organized under routes/ (fs, exec, mcp, bridges), shell/bridge/idle logic moved to dedicated modules, and the main file reduced to startup sequence and server wiring.

  • Extract filesystem API (/fs/*) into routes/fs.ts with shared path-parameter helpers
  • Extract code execution (/exec) and MCP (/mcp) endpoints into routes/exec.ts and routes/mcp.ts
  • Move shell server (ttyd supervision, WebSocket proxy) to shell-server.ts
  • Move bridge reverse-proxy logic to bridge-proxy.ts; bridge config stays in bridges.ts
  • Extract idle-timeout tracking to idle.ts module with public API
  • Move language normalization and execution dispatch to operations.ts for reuse
  • Add unit tests for bridge matching, language normalization, and route parameters
  • main.ts now reads as startup sequence → HTTP server assembly, with feature logic in dedicated modules

https://claude.ai/code/session_018RzDtc14x6oxeZtVARn4fD

- main.ts (1360 lines) is now startup sequence + wiring (~325 lines): ttyd
  supervision and the /shell proxy live in shell-server.ts, bridge reverse
  proxies in bridge-proxy.ts, HTTP handlers in routes/*, idle shutdown in
  idle.ts
- fix Express 5 wildcard params: String(req.params.path) comma-joined the
  segment array, corrupting every nested /fs path and DELETE /bridges/<path>;
  added wildcardPath() with regression tests
- dedupe the /fs root vs wildcard handlers, the bridge URL rewrite (HTTP vs
  WebSocket copies), and language normalization (main.ts vs mcp.ts)
- HEAD /fs no longer reads whole files for the MIME type; archiver errors no
  longer throw from an event handler (process-crash risk); unmatched WebSocket
  upgrades are now destroyed instead of left hanging
- fix pre-existing lint failures, normalize formatting, update AGENTS.md
  project structure

https://claude.ai/code/session_018RzDtc14x6oxeZtVARn4fD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants