question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SubApps/SubRouters do not inherit :params

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
talentlessguycommented, Apr 8, 2021

fix is available in the 1.2.23 version

0reactions
talentlessguycommented, Apr 8, 2021

I’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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using @inheritParams to inherit from a @noRd block #1159
However it would appear that it is not possible to use @inheritParams to inherit parameters from a function documented with the @noRd tag....
Read more >
r - How to use @inheritParams on single parameters when ...
I would like to document an R function and inherit individual parameter documentation from other functions when multiple parameter names match.
Read more >
Inherit parameters from another function. in hadley/roxygen3 ...
This tag will bring in all documentation for parameters that are undocumented in the current function, but documented in the source function ...
Read more >
Reusing documentation
You can inherit documentation from other topics in a few ways: @inheritParams source_function inherits just the parameter documentation from source_function() .
Read more >
CreatePrivateObjectSecurityWith...
If there is no parent container, this parameter is NULL. ... If this flag is not set, the new DACL does not inherit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found