Refactor: pass adminApiMiddleware into createKoaApp(); rename koaMiddleware to routesMiddleware#1849
Merged
pmcelhaney merged 4 commits intomainfrom Apr 14, 2026
Conversation
…leware to routesMiddleware Agent-Logs-Url: https://github.com/counterfact/api-simulator/sessions/d1c59b39-f61d-4f73-931b-bd773553d881
Copilot
AI
changed the title
[WIP] Fix adminApiMiddleware construction in createKoaApp
Refactor: pass adminApiMiddleware into createKoaApp(); rename koaMiddleware to routesMiddleware
Apr 14, 2026
pmcelhaney
requested changes
Apr 14, 2026
Collaborator
There was a problem hiding this comment.
Remove this line and remove registry from the arguments
Contributor
Author
There was a problem hiding this comment.
Done in 3b56164. Removed debug("routes", registry.routes) and the registry parameter from createKoaApp().
pmcelhaney
approved these changes
Apr 14, 2026
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
adminApiMiddlewarewas being constructed insidecreateKoaApp(), coupling middleware lifecycle to the factory and making parallel server setups awkward. This moves construction to the caller and renames the ambiguouskoaMiddlewaretoroutesMiddlewarethroughout. Theregistryparameter has also been removed fromcreateKoaApp()as it was only used for a debug log line that has been dropped.Before:
After:
Original Prompt
adminApiMiddlewareshould not be constructed insidecreateKoaApp(). That's making the parallel servers implementation difficult.Also change the name of
koaMiddlewaretoroutesMiddleware.Manual acceptance tests
startAdminApi: truestill serves admin API routes at/_counterfact/api/healthstartAdminApi: falseresults in no admin API routes being mountedroutesMiddlewareproperty returned fromcounterfact()is a callable Koa middleware functionGET /pets) respond correctly after the refactor/counterfact/swaggerstill loads correctlyTasks
koaMiddleware→routesMiddlewareinsrc/server/koa-middleware.ts(export) and all callsitesContextRegistryparam fromcreateKoaApp(); replaced with optionaladminApiMiddleware?: Koa.Middlewareregistryparam fromcreateKoaApp()and dropped thedebug("routes", registry.routes)line that was its only useadminApiMiddlewareconstruction +startAdminApiguard intosrc/app.ts(the caller)koaMiddleware→routesMiddlewareincounterfact()