Skip to content

refactor(server side): split index.ts into focused modules - #1

Open
diplexion wants to merge 1 commit into
deyoyk:mainfrom
diplexion:refactor/server-index-split
Open

refactor(server side): split index.ts into focused modules#1
diplexion wants to merge 1 commit into
deyoyk:mainfrom
diplexion:refactor/server-index-split

Conversation

@diplexion

Copy link
Copy Markdown

Hey deyo i really interesting of ur project cuz i need something like for testing my servers but ngrok is ass 🗡️ so and i decided help u with develop and make this refactoring <3

Result of refactoring

Why

server/src/index.ts was 635 lines and mixed several unrelated concerns:
routing, subdomain/host utilities, the binary WS envelope protocol, the
TunnelDO durable object (the actual tunnel logic), and ~250 lines of
inline HTML templates. This made the core tunnel logic hard to find and
hard to unit-test in isolation from Cloudflare-specific types.

What changed

Pure code move, no behavior change:

  • types.tsEnv, PendingRequest, ProxyResponse
  • subdomain.ts — host/subdomain parsing, sanitization, sharding
  • envelope.ts — binary request/response envelope (de)serialization
  • tunnel-do.tsTunnelDO durable object (WS lifecycle, proxying, auth)
  • html/root.ts / html/offline.ts — inline HTML templates
  • index.ts — thin fetch handler / routing only (~60 lines)

Testing

  • npx tsc --noEmit passes with no errors
  • npx wrangler deploy --dry-run bundles successfully and resolves the
    TunnelDO durable object binding correctly

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.

1 participant