The example you show using router.get()
or app.get()
does not actually occur. router.get()
does not do partial matches unless you're using wildcards or regexes.
I verified that in this simple test app:
const express = require('express');
const app = express();
app.get("/task/", (req, res) => {
res.send("got /task");
});
app.get("/task/seed", (req, res) => {
res.send("got /task/seed");
});
app.listen(80);
When you request /task/seed
, you get the message got /task/seed
so, it does route correctly.
On the other hand, router.use()
does do partial matches so this problem could occur if your actual code was using .use()
, not .get()
. In that case, you just need to either switch to the verb-specific .get()
instead of using the generic .use()
or you need to order your routes from the most specific to the least-specific so that the most-specific declaration gets a chance to match first:
router.use("/task/seed/", Controller.seed);
router.use("/task/", Controller.retrieveAll);
In case you're curious, the two main differences between router.use()
and router.get()
are:
.get()
only matches GET requests while .use()
matches all HTTP verbs.
.get()
only does full path matches while .use()
will match any URL path that starts with what you specify.