-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
keep query params on proxy #325
Conversation
Can you use https://www.npmjs.com/package/fast-querystring/v/1.1.0 instead? |
@mcollina should be updated to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Since Matteo proposed changes to benefit performance, I think we can lower the amount of object creations and repetition
In line 337, dest === path
because we initialize dest
like so:
let dest = request.raw.url.slice(0, queryParamIndex !== -1 ? queryParamIndex : undefined)
We are essentially redoing this inside the function you've added using split
, so I propose a small simplification where you call extractUrlComponents
a little earlier, maybe right after where queryParamIndex
is defined, and initialize dest
with path
Finally, inside extractUrlComponents
, we don't want to create an object if queryString
doesn't exist. Instead, we can initialize with null
and reassign if necessary
Here's what it'd look like
function extractUrlComponents(urlString) {
const [path, queryString] = urlString.split("?");
const components = {
path,
queryParams: null,
};
if (queryString) {
components.queryParams = qs.parse(queryString);
}
return components;
}
// ...
// ...
// delete -> const queryParamIndex = request.raw.url.indexOf("?");
const { path, queryParams } = extractUrlComponents(request.url);
let dest = path;
// ...
// ...
// instead of checking queryParamIndex we check if queryParams is truthy
if (queryParams) {
dest += `?${qs.stringify(queryParams)}`;
}
@gurgunday great feedback! this should be updated now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@fastify/http-proxy](https://togithub.com/fastify/fastify-http-proxy) | [`9.2.1` -> `9.3.0`](https://renovatebot.com/diffs/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify-http-proxy (@​fastify/http-proxy)</summary> ### [`v9.3.0`](https://togithub.com/fastify/fastify-http-proxy/releases/tag/v9.3.0) [Compare Source](https://togithub.com/fastify/fastify-http-proxy/compare/v9.2.1...v9.3.0) #### What's Changed - Listen only to IPv4 network for websockets tests by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify-http-proxy/pull/316](https://togithub.com/fastify/fastify-http-proxy/pull/316) - opt to validate incoming data before proxy is executed by [@​kovalenp](https://togithub.com/kovalenp) in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - build(deps-dev): bump [@​typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin) from 5.62.0 to 6.2.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/318](https://togithub.com/fastify/fastify-http-proxy/pull/318) - build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/320](https://togithub.com/fastify/fastify-http-proxy/pull/320) - perf: use `node:` prefix to bypass require.cache call for builtins by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/321](https://togithub.com/fastify/fastify-http-proxy/pull/321) - build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/323](https://togithub.com/fastify/fastify-http-proxy/pull/323) - test(websocket): optimize split param by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/326](https://togithub.com/fastify/fastify-http-proxy/pull/326) - keep query params on proxy by [@​dancastillo](https://togithub.com/dancastillo) in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) - chore(package): explicitly declare js module type by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/327](https://togithub.com/fastify/fastify-http-proxy/pull/327) #### New Contributors - [@​kovalenp](https://togithub.com/kovalenp) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - [@​dancastillo](https://togithub.com/dancastillo) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) **Full Changelog**: fastify/fastify-http-proxy@v9.2.1...v9.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@fastify/http-proxy](https://togithub.com/fastify/fastify-http-proxy) | [`9.2.1` -> `9.3.0`](https://renovatebot.com/diffs/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>fastify/fastify-http-proxy (@​fastify/http-proxy)</summary> ### [`v9.3.0`](https://togithub.com/fastify/fastify-http-proxy/releases/tag/v9.3.0) [Compare Source](https://togithub.com/fastify/fastify-http-proxy/compare/v9.2.1...v9.3.0) #### What's Changed - Listen only to IPv4 network for websockets tests by [@​mcollina](https://togithub.com/mcollina) in [https://github.com/fastify/fastify-http-proxy/pull/316](https://togithub.com/fastify/fastify-http-proxy/pull/316) - opt to validate incoming data before proxy is executed by [@​kovalenp](https://togithub.com/kovalenp) in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - build(deps-dev): bump [@​typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin) from 5.62.0 to 6.2.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/318](https://togithub.com/fastify/fastify-http-proxy/pull/318) - build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/320](https://togithub.com/fastify/fastify-http-proxy/pull/320) - perf: use `node:` prefix to bypass require.cache call for builtins by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/321](https://togithub.com/fastify/fastify-http-proxy/pull/321) - build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/fastify/fastify-http-proxy/pull/323](https://togithub.com/fastify/fastify-http-proxy/pull/323) - test(websocket): optimize split param by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/326](https://togithub.com/fastify/fastify-http-proxy/pull/326) - keep query params on proxy by [@​dancastillo](https://togithub.com/dancastillo) in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) - chore(package): explicitly declare js module type by [@​Fdawgs](https://togithub.com/Fdawgs) in [https://github.com/fastify/fastify-http-proxy/pull/327](https://togithub.com/fastify/fastify-http-proxy/pull/327) #### New Contributors - [@​kovalenp](https://togithub.com/kovalenp) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/312](https://togithub.com/fastify/fastify-http-proxy/pull/312) - [@​dancastillo](https://togithub.com/dancastillo) made their first contribution in [https://github.com/fastify/fastify-http-proxy/pull/325](https://togithub.com/fastify/fastify-http-proxy/pull/325) **Full Changelog**: fastify/fastify-http-proxy@v9.2.1...v9.3.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/redwoodjs/redwood). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40Ni4wIiwidXBkYXRlZEluVmVyIjoiMzcuNDYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Checklist
closes: #322
npm run test
andnpm run benchmark
and the Code of conduct