Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subapps not receiving params from parent apps #314

Closed
esthedebeste opened this issue Sep 12, 2021 · 4 comments · Fixed by #315
Closed

Subapps not receiving params from parent apps #314

esthedebeste opened this issue Sep 12, 2021 · 4 comments · Fixed by #315
Labels
bug Something isn't working

Comments

@esthedebeste
Copy link
Contributor

Describe the bug

A parent app that does app.use("/:path", subapp) doesn't pass req.params.path to the subapp.

To Reproduce

Code to reproduce the behavior:

import { App } from "@tinyhttp/app";
const subapp = new App().get("/", (req, res) => {
  if (req.params.test == null) {
    res.send("req.params.test not passed");
  } else {
    res.send(`req.params.test passed: ${req.params.test}`);
  }
});
new App()
  .use("/:test", subapp)
  .listen(8080, () => console.log("listening on http://localhost:8080"));

Expected behavior

req.params.test is passed to the subapp

Versions

  • node: 16.3.0
  • @tinyhttp/app: 2.0.3
@esthedebeste esthedebeste added the bug Something isn't working label Sep 12, 2021
@talentlessguy
Copy link
Member

wasn't it fixed before ?

#242

if it appeared again, can you tell please which version still works?

@esthedebeste
Copy link
Contributor Author

I thought so too, but looking at the test for 242, it looks like it didn't test if req.params got anything from the URL.

@talentlessguy
Copy link
Member

@tbhmens got you, not cool then

any ideas on a possible fix?

@esthedebeste
Copy link
Contributor Author

I think I've found a solution by replacing
https://github.com/tinyhttp/tinyhttp/blob/master/packages/app/src/app.ts#L321
with req.params = { ...req.params, ...params },
I'll make a PR in a sec 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants