I am seeking a way to capture a req.params item in an interception layer:
Imagine having an instance of an express server application like this:
const app = express();
along with an interception layer:
app.use((req, res, next) => {
console.log(req.params.myParam);
next();
})
and multiple endpoints similar to this one:
app.get('/anything/:myParam', (req, res) => res.send('hello'))
Currently, 'undefined' is being logged, which is expected as the parameter name is not yet defined when the middleware within "use" is executed. However, I urgently need to access the value of myParam in this interception layer while adhering to the following constraints:
- I know the specified name of the parameter in the intercepted endpoints (myParam)
- I do not have knowledge of how the URL structure is set up in the intercepted endpoints (it could be /anything/:myParam, or /:myParam/anything, etc.)
Is there a solution available for this particular scenario?