Skip to content
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

Merged
merged 5 commits into from
Oct 22, 2023

Conversation

dancastillo
Copy link
Contributor

Checklist

closes: #322

index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@mcollina
Copy link
Member

mcollina commented Oct 7, 2023

Can you use https://www.npmjs.com/package/fast-querystring/v/1.1.0 instead?

@dancastillo
Copy link
Contributor Author

@mcollina should be updated to use fast-querystring now

Copy link
Member

@gurgunday gurgunday left a 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)}`;
      }

@dancastillo
Copy link
Contributor Author

@gurgunday great feedback! this should be updated now

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

index.js Outdated Show resolved Hide resolved
@gurgunday gurgunday merged commit 330c91e into fastify:master Oct 22, 2023
15 checks passed
renovate bot added a commit to redwoodjs/redwood that referenced this pull request Nov 15, 2023
[![Mend Renovate logo
banner](https://app.renovatebot.com/images/banner.svg)](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)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@fastify%2fhttp-proxy/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@fastify%2fhttp-proxy/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>fastify/fastify-http-proxy
(@&#8203;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
[@&#8203;mcollina](https://togithub.com/mcollina) in
[fastify/fastify-http-proxy#316
- opt to validate incoming data before proxy is executed by
[@&#8203;kovalenp](https://togithub.com/kovalenp) in
[fastify/fastify-http-proxy#312
- build(deps-dev): bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.62.0 to 6.2.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#318
- build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#320
- perf: use `node:` prefix to bypass require.cache call for builtins by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#321
- build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#323
- test(websocket): optimize split param by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#326
- keep query params on proxy by
[@&#8203;dancastillo](https://togithub.com/dancastillo) in
[fastify/fastify-http-proxy#325
- chore(package): explicitly declare js module type by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#327

#### New Contributors

- [@&#8203;kovalenp](https://togithub.com/kovalenp) made their first
contribution in
[fastify/fastify-http-proxy#312
- [@&#8203;dancastillo](https://togithub.com/dancastillo) made their
first contribution in
[fastify/fastify-http-proxy#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>
jtoar pushed a commit to redwoodjs/redwood that referenced this pull request Nov 16, 2023
[![Mend Renovate logo
banner](https://app.renovatebot.com/images/banner.svg)](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)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/@fastify%2fhttp-proxy/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@fastify%2fhttp-proxy/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@fastify%2fhttp-proxy/9.2.1/9.3.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>fastify/fastify-http-proxy
(@&#8203;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
[@&#8203;mcollina](https://togithub.com/mcollina) in
[fastify/fastify-http-proxy#316
- opt to validate incoming data before proxy is executed by
[@&#8203;kovalenp](https://togithub.com/kovalenp) in
[fastify/fastify-http-proxy#312
- build(deps-dev): bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.62.0 to 6.2.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#318
- build(deps-dev): bump tsd from 0.28.1 to 0.29.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#320
- perf: use `node:` prefix to bypass require.cache call for builtins by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#321
- build(deps-dev): bump express-http-proxy from 1.6.3 to 2.0.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[fastify/fastify-http-proxy#323
- test(websocket): optimize split param by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#326
- keep query params on proxy by
[@&#8203;dancastillo](https://togithub.com/dancastillo) in
[fastify/fastify-http-proxy#325
- chore(package): explicitly declare js module type by
[@&#8203;Fdawgs](https://togithub.com/Fdawgs) in
[fastify/fastify-http-proxy#327

#### New Contributors

- [@&#8203;kovalenp](https://togithub.com/kovalenp) made their first
contribution in
[fastify/fastify-http-proxy#312
- [@&#8203;dancastillo](https://togithub.com/dancastillo) made their
first contribution in
[fastify/fastify-http-proxy#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>
@dancastillo dancastillo deleted the query-params-on-proxy branch December 27, 2023 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in rewrite prefix when having query params and url params in the URL
3 participants