refactor: split server.ts into routed modules - #36
Merged
Conversation
Replace the 1400-line prefix-matching dispatcher in src/server.ts with a find-my-way router and one route module per domain (auth, accounts, dashboard, repository, mentions, projects, notifications). GraphQL documents move to src/server/graphql, the dependents HTML parser becomes pure logic in src/utils with unit tests, and repeated body/repo/redirect handling is centralised in http.ts and routes/shared.ts. Routes now match by method and exact path: a wrong verb answers 405 with an Allow header and an unknown /api/* path answers a JSON 404 instead of index.html. The esbuild bundle gets a createRequire banner so the CommonJS router loads under ESM.
debba
force-pushed
the
refactor/server-routes
branch
from
September 3, 2026 14:04
8f3774d to
b693f20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/server.tswas a 1475-line file mixing bootstrap, GraphQL documents, HTML scraping and a long chain ofurl.startsWith(...)checks. This PR splits it up and puts routing on find-my-way, the router used by Fastify, while keeping Node's nativehttprequest/response model.src/server.tssrc/server/app.tssrc/server/router.tsRouteContext, 405 handling)src/server/spa.tssrc/server/routes/*src/server/graphql/*src/utils/dependents.tsRepeated code is centralised:
parseJsonBody,sendPayload,sendRedirectinhttp.ts;requireRepo/sendErrorinroutes/shared.ts.Behaviour changes
405with anAllowheader and the same JSON body as before; per-handlerreq.methodchecks are gone./api/*path answers a JSON404instead ofindex.html.Build
find-my-way is CommonJS and the ESM bundle produced by esbuild failed at startup with
Dynamic require of "node:assert" is not supported. Thebuildscript now adds the standardcreateRequirebanner.Verification
npm run typecheck: no errors in the new code (the 5 pre-existing errors in views,openaiDigest.tsandcolors.test.tsare untouched).npm test: 23 files, 116 tests passing, including 8 new ones for the router and the dependents parser.node dist/server.jsandtsx src/server.ts: SPA routes, static files, 401 without login, 400, 404 and 405 all respond as expected.