I want to add a string to a req.url in Express. The string looks like this:
?id=someID&product=bag
I don't have an access to client html or server. All I get from client it's just a GET request without any parameters. So I tried to make middleware which would add query string and then I will parse it like always. The idea was:
// Middleware
const addQuery = (req, res, next) => {
req.url = req.url + `?id=someID&product=bag`;
next();
}
And then in request handler:
router.get('/', addQuery, (req, res) => {
console.log(req.query.id);
console.log(req.query.product);
});
But it gives me undefined. I can't use any client side js and I can't use server side coding. Not my origin sends me this request.
So how to add query string to express request and then successfully parse it?