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

Nitro DevProxy ignores target basePath #1643

Closed
cs8898 opened this issue Aug 26, 2023 · 6 comments
Closed

Nitro DevProxy ignores target basePath #1643

cs8898 opened this issue Aug 26, 2023 · 6 comments

Comments

@cs8898
Copy link

cs8898 commented Aug 26, 2023

Environment

NitroPack

nitropack@latest:
  version "2.6.1"

Nitro Config

export default defineNitroConfig({
    devProxy: {
        "/api": {
           target: "http://localhost:3001/api"
        }
    }
});

Node

v18.12.1

Yarn

1.22.19

Reproduction

Sample is provided in https://github.com/cs8898/nitro_devproxy_mre

Describe the bug

Problem

Nitro devProxy drops basepath of proxied server (only accepts Protocol, Host and Port of URL)

Expected
http://nitro:3000/api/foo => http://server:3001/api/foo
Observed
http://nitro:3000/api/foo => http://server:3001/foo

Additional context

No response

Logs

No response

@cs8898
Copy link
Author

cs8898 commented Aug 26, 2023

@cs8898
Copy link
Author

cs8898 commented Aug 26, 2023

Actually httpxy is ignoring the BaseURL
Nitro just drops the Route Segment of the defined Router

cs8898/nitro_devproxy_mre@f15a35f

@jonasolesen
Copy link

FWIW, I tried looking into this and also found the bug to be in httpxy. When setting the target path, it is using a path property on an URL object. This property does not exist, and changing it to pathname seems to have solved the issue: https://github.com/jonasolesen/httpxy/commit/0919f9d0be5b4749bb9d40c6f9557e0137712818

@cs8898
Copy link
Author

cs8898 commented Aug 26, 2023

that seems to help Thanks

https://developer.mozilla.org/en-US/docs/Web/API/URL/pathname

@cs8898
Copy link
Author

cs8898 commented Aug 26, 2023

@jonasolesen Works also for me, i can confirm, that solved the Problem.

I will close that here, if you could create an PR that would be great

@jonasolesen
Copy link

@cs8898 That's great! I've submitted an issue and a PR- hoping the fix is as simple as it seemed 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants