SubApps/SubRouters do not inherit :params
See original GitHub issueDescribe the bug
Mounting a SubApp onto an App on a given path results in the path being interpreted literally - wildcards are not passed over to the route, and neither are parameters.
To Reproduce
Steps to reproduce the behavior:
// subApp.js
import { App } from "@tinyhttp/app";
const app = new App();
app.get("/profile", (req, res) => res.send("hit"));
export default app;
// server.js
import { App } from "@tinyhttp/app";
import subApp from "./subApp.js";
const app = new App();
app.use("/users/:userID", subApp);
app.get("*", (req, res) => {
return res.send("missed");
});
Making a request of GET /users/123/profile
results in missed - doesn’t seem to match params.
Making a request of GET /users/:userID/profile
results in a hit - as in the literal string “:userID”.
I haven’t read the source code yet but I assume mounting subapps seems to discard any custom routes and treats it as a literal string?
Expected behavior
I expected subApps mounted on a route to inherit the parameters setup of the route.
Versions
node
: 15.9.0@tinyhttp/app
: 1.2.20
Additional context
Express inherits the wildcards/custom routing when mounting subrouters onto routes, but by default it does not share parameters unless {mergeParams: true} is passed as an option to the router constructor.
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
fix is available in the
1.2.23
versionI’m happy to announce that the bug has been fixed!
@zkldi here are passing tests for proving that:
https://github.com/talentlessguy/tinyhttp/blob/da3cdf336753b2bdf9a9cece654bcffe56c71652/__tests__/core/app.test.ts#L773-L800
currently running the build process, patch update coming soon