req.query is not being applied into the target
Closed this issue · 3 comments
I'm not sure if this is supposed to happen, I'm just trying to set a querystring into the target url, here is an example to try
npm i restana fast-gateway
const restana = require("restana");
const gateway = require("fast-gateway");
const app = gateway({
pathRegex: "",
routes: [
{
prefix: "/some-path",
target: `http://localhost:3001/some-other-path`,
hooks: {
async onRequest(req, res) {
req.query = {
some: "thing",
};
},
},
},
],
});
restana({})
.get("/some-other-path", (req, res) => {
console.log(req.query); // < here the url has no query
res.send({});
})
.start(3001)
.then(() => console.log("ready 3001"));
app
.start(3000)
.then(() => console.log("ready 3000 || try > http://localhost:3000/some-path"));
So getting into http://localhost:3000/some-path logs an empty object, query is not being forwarded. Is there a way of doing this?
Thanks!
as a note: I know there is another prop queryString
on the hook but I need to set the querystring dinamically from the current request
Hi @pjnovas thanks for catching this missing feature. One can update the request URL and it will pass the query parameters to the origin, but we should have an easier way of handling this.
I like your idea of just editing the req.query object. I will come back to you ASAP
Hi @pjnovas, this feature is available in v2.5.0
Thanks for contributing!