Skip to content

feat: add app.listRoutes with sub-application support - #7531

Open
bjohansebas wants to merge 3 commits into
masterfrom
feat/list-routes-subapps
Open

bjohansebas wants to merge 3 commits into
masterfrom
feat/list-routes-subapps

Conversation

@bjohansebas

@bjohansebas bjohansebas commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Add app.listRoutes() and expose mounted sub-application routers for nested route inspection, preserving lazy initialization and request handling.

Depends on pillarjs/router#174 plus wrapper support; router is temporarily pinned to that Git commit.

@bjohansebas

Copy link
Copy Markdown
Member Author

cc: @logaretm @UlisesGascon

Comment thread package.json Outdated
"qs": "^6.16.0",
"range-parser": "^1.2.1",
"router": "^2.2.0",
"router": "git+https://github.com/bjohansebas/router.git#e59071e415da5983ab901f5d81597b424fda4bdf",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: This commit isn't in your PR yet, I assume it will?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, but I rebased, so the commit hashes changed. To test it locally, you’ll need to use the latest commit hash from that PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the wrapper change in listRoutes, there's no handle.router check. I think it had this?

if (!route) {
  const handle = layer.handle
  const candidate = Array.isArray(handle.stack) ? handle : handle.router  // L469

  if (candidate && Array.isArray(candidate.stack)) {
    router = candidate
  }
}

Can you double check if it is there?

Replace the Git dependency with router@^2.3.0 and restore allow-git=none. Extend sub-application coverage for strict routing and parent restoration after rejected promises.

The sub-application tests still require wrapper support in router, which is not included in 2.3.0.
Document that app.listRoutes() initializes application routers and captures their routing settings. Add tests covering configuration changes after inspecting empty applications and mounted sub-applications.

@subhiandrews subhiandrews left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code-check review

2 warning, 1 suggestion

Reviewed with code-check · Apache-2.0

Comment thread lib/application.js
return this.router.route(path);
};

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · docs

Added comments make up 6.8% of the added lines, over the 3% cap (docs-metrics). All 17 comment lines are in this file, and the 13-line JSDoc on a one-line delegating method is most of them. Two points are worth keeping: nested routes are not expanded, and calling the method initializes routers. Cut the block to those two or three lines.

Suggested change
/**
/**
* List routes and mounted routers on this app. Sub-app entries expose `router`; nested routes are not expanded.
* Initializes the routers involved, so set `case sensitive routing` and `strict routing` first.
*
* @return {Array}
* @public
*/

code-check · doc-skeptic

Comment thread package.json
"qs": "^6.16.0",
"range-parser": "^1.2.1",
"router": "^2.2.0",
"router": "^2.3.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning · dependency

The PR description says app.listRoutes() depends on the unmerged pillarjs/router#174 plus a separate wrapper-support commit, and that router is 'temporarily pinned to that Git commit'. The diff does not pin anything. It only changes the range to "router": "^2.3.0". app.listRoutes() calls this.router.listRoutes() (lib/application.js:287), and sub-app entries only expose router if the router package honours the new handler router property. If no published router 2.3.x contains both changes, installing from the registry either fails or gives a router without listRoutes. In that case app.listRoutes() throws a TypeError and test/app.listRoutes.js fails. Severity is warning rather than the critical one reviewer gave: I could not confirm whether such a release exists, because node_modules is not installed in the worktree. The mismatch between the description and package.json is confirmed. Do not merge until router publishes both features and the range points at that release.

Suggested change
"router": "^2.3.0",
"router": "<released version that contains listRoutes and wrapper support>",

code-check · architect, pragmatist, skeptic

Comment thread lib/application.js
* @public
*/

app.listRoutes = function listRoutes() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion · side-effect

The router getter on mounted_app (line 240) returns fn.router. That is the sub-app's lazy getter (line 69), which builds the Router and captures 'case sensitive routing' and 'strict routing' at that moment. So app.listRoutes(), a read-only inspection call, initializes every directly mounted sub-app router (nested sub-apps are not touched), and settings changed on those sub-apps afterwards are silently ignored. The PR describes this as 'preserving lazy initialization', yet calling listRoutes ends lazy initialization for every directly mounted sub-app. Severity is suggestion rather than the warning one reviewer gave. The behavior is deliberate: it is documented in the JSDoc and covered by a test. It also matches existing Express semantics, where any early access to app.router (app.route, app.use) already freezes these settings for the parent app. A side-effect-free inspection path would still remove the order dependence.

code-check · lang-javascript, skeptic

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