To add wildcard routing to cover everything under and including a path with Node.js Express.js, we can add multiple routes.
For instance, we write
const express = require("express");
const app = express.createServer();
const fooRoute = (req, res, next) => {
res.end("Foo Route\n");
};
app.get("/foo*", fooRoute);
app.get("/foo", fooRoute);
app.listen(3000);
to add the /foo* route to handle any URLs that starts with /foo
.
And we add the /foo route to handle request with URL /foo.
We call fooRoute
to handle both kinds of requests.