talentlessguy/tinyhttp






The issue has been solved
Some router paths don't work if router is mounted after defining routes #278
weedz posted onGitHub
Describe the bug
Can not find the correct route when using sub-apps.
To Reproduce
Steps to reproduce the behavior:
The following code does not work as intended:
import { App } from '@tinyhttp/app';
const app = new App()
const router = new App();
router.get("/list", (req,res) => {
console.log("router/list");
res.send("router/list");
});
router.get("/find", (req,res) => {
console.log("router/find");
res.send("router/find");
});
app.use("/router", router);
app.listen(3000);
I can't request /router/find
but /router/list
works.
If I instead "use" router
before we define any routes it works:
import { App } from '@tinyhttp/app';
const app = new App()
const router = new App();
app.use("/router", router); // <-- HERE, we "use" router before we add any routes
router.get("/list", (req,res) => {
console.log("router/list");
res.send("router/list");
});
router.get("/find", (req,res) => {
console.log("router/find");
res.send("router/find");
});
app.listen(3000);
Expected behavior
Should not matter where the use
is called? When requesting /router/find
you should see router/find
instead of Not Found
.
Versions
node
: 14.16.1@tinyhttp/app
: 1.3.11
Additional context
Add any other context about the problem here.