I am trying to use an expression to parse a request if certain parameters are set and a small piece of code is executed before the actual routing. A use case is to capture a specific value that can be set no matter which link is used. I use the express' function to pass stuff to the next possible rule using next ().
So far I have tried - at the very top of the whole app.get / post-rule-block block:
app.get('[?&]something=([^&#]*)', function(req, res, next) { var somethingID = req.params.something;
and:
app.param('something', function(req, res, next) { var somethingID = req.params.something; console.log("Something: "+somethingID); next(); }) app.get('/', site.index);
An example of what should be called:
URL: www.example.com/?something=10239 URL: www.example.com/superpage/?something=10239 URL: www.example.com/minisite/?anything=10&something=10239
Unfortunately, none of my solutions actually worked, and all that happens is that the following matching rule is triggered, but the little function above is never executed. Does anyone have an idea how to do this?
EDIT: I understand that the param example did not work, since I do not use the specified parameter in any other routing rule after that, and it will only run then.
I also understand that the logic implies that Express ignores the request and is usually parsed inside the function after routing has already occurred. But, as already mentioned, I need this to be a βroute agnosticβ and work with any URL processed in this application.
source share