Repository navigation
feat: add app.listRoutes with sub-application support - #7531
bjohansebas wants to merge 3 commits into
Conversation
| "qs": "^6.16.0", | ||
| "range-parser": "^1.2.1", | ||
| "router": "^2.2.0", | ||
| "router": "git+https://github.com/bjohansebas/router.git#e59071e415da5983ab901f5d81597b424fda4bdf", |
There was a problem hiding this comment.
Q: This commit isn't in your PR yet, I assume it will?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| return this.router.route(path); | ||
| }; | ||
|
|
||
| /** |
There was a problem hiding this comment.
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.
| /** | |
| /** | |
| * 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
| "qs": "^6.16.0", | ||
| "range-parser": "^1.2.1", | ||
| "router": "^2.2.0", | ||
| "router": "^2.3.0", |
There was a problem hiding this comment.
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.
| "router": "^2.3.0", | |
| "router": "<released version that contains listRoutes and wrapper support>", |
code-check · architect, pragmatist, skeptic
| * @public | ||
| */ | ||
|
|
||
| app.listRoutes = function listRoutes() { |
There was a problem hiding this comment.
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
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;
routeris temporarily pinned to that Git commit.