I have a middleware function that takes a query string value and turns it into
I am using Express 4 and Node.js. I have a route defined for /:module/:page.aspx
and am using req.params
and req.query
values across a number of middleware functions.
app.get('/:module/:page.aspx', catchEncodedQuery, doSomeStuff, doOtherStuff);
I have one middleware function that appears first, which catches certain requests which have a query string value that can be transformed into a new req.url
that I set for use further on in the middleware chain. Basically, I want to proceed as though the un-encoded form of this query string value was the request URL the whole time.
function catchEncodedQuery(req, res, next) {
if (
// req meets some specific criteria
) {
req.url = myUnencodeFunction(req.query.url_str);
next();
} else {
next();
}
};
But I would also like req.params
and req.query
to reflect this new URL. I could just parse the new URL myself and reassign these values to req.params
and req.query
, but I'm wondering if there's a better way to do this that leverages Express's existing URL-parsing functionality.