-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Simplify our "advanced" proxy #3366
Comments
@Timer wondering that how to configure the option.agent prop with create react app. The reason why I need this option is that I am behind the cooperate proxy and trying to hit API endpoint in outside the cooperate network. Thanks! |
@Timer, the new approach looks good but I have one request based on issues we've run into with our team. It would be helpful if the In our environment, developers can test against the back-end running locally, or against a VM, or against a cloud server. So they modify their One solution might be to support environment variables in the target, for example:
Thanks! |
I think that If you enable user to pass the proxy config as follows then it will handle all the use cases. config object can have any configuration that http-proxy-middleware accepts. So if people want to use features like pathRewrite they can simply use it.
|
My need is: Right now we can define some proxied paths using the
In my own project I managed to get this to work with
and changing the The first change is needed because otherwise the proxy will be bypassed if your html file is called The second change is needed to tell Once you have these changes, you are able to write proxy rules like this:
Is this something you'd like to support? |
@gaearon asked me to continue #3204 on this issue. To summarize:
|
Does anyone want to work on a proposal that would address the above issues together? It could even be something radical like detecting |
@maxhallinan @gaearon I am currently working on a large banking app which has 5 + different environments before code land in to Prod. My project is not on React but using webpack and node http proxy to enable front end engineers to hit any of those environments from their local computer. This is how I handle multiple env problem. npm run dev -- --env uat When developer runs the above code I get the URL mapping for UAT and create all the required proxy mappings. Alternatively developer can pass a valid http url as the end point since we allow people to spin up backend in cloud too. Thanks. |
Yeah, 3245 was my concern. I had to eject CRA and get rid of proxy completely. Is it possible to add something like
in package.json by default, and write documentation and deprecation warnings for everybody who is updating CRA or new users. Anyway no one can't predict the backend API chosen by end user. PS: Thanx everybody for a great work. Even just ejecting CRA saving a ton of work for advanced developers like me. Please keep up a great work! |
I'm not sure what you mean. Proxy is not enabled unless you add a Let me reopen #3245 because it seems like there is either a legitimate bug or a misunderstanding there. |
I was just thinking about this as well. I think points 1 and 2 (first example) from @Timer's original comment make sense. I also like @gaearon's idea of looking for
Option 3 is interesting because of the potential for advanced use cases. It also allows the first two options to be simpler/less configurable. I'm not exactly sure how option 3 would work. I guess you would just be providing a custom |
I would vote for proxy.js and this allows people to use any option http-proxy-middleware gives also we can add multiple environment support as well. E.g. UAT, SIT and PROD |
@gaearon @Timer @iansu requesting your feedback. Proposal Iteration 01:As a create react app user I want to configure proxy middleware easily so that I can connect with API endpoints without getting browser security warnings. New proxy solution will add the flexibility to users to use all the options that http-proxy-middleware provides. Further solution supports multi environments as well. E.g. Dev, Test, Acceptance and Production. How to use: Basic: With environment: Sample configuration (proxy.js):
Description:
|
I would just leave (1) and (3). (1) is for simple use cases. (3) is for everything else. We've seen so many edge cases I'm not sure there is any value in a "middle" solution. We could provide a few copy-pasteable recipes for common scenarios that used to be solved by (2). |
and anyway someone will be able to release a dedicated package to simplify the configuration of the proxy
|
Except for backwards compatibility, a proxy target string in
I'm not sure if this makes sense. It would be the ideal for me. Thank you everyone for sharing ideas here. Anything which enables me to configure the proxy via the environment will help me. |
I think this makes sense to me. We introduced |
To everyone: is this sufficient for your use cases? |
#3845 This one gives satisfy my requirement. |
This is perfect for us. Thank you. |
@iansu @gaearon How about:
By this way, the enabling logic is simpler, and does not need to looking for proxy.js/json file |
One approach I took a while ago was to customize the start script to allow for "templated" strings, such as : {
proxy: "${MY_PROXY_VAR}"
} the string would be evaluated in the context of process.env. It's very simple for the user to use environment variables for single proxy entry. |
@doronnac Yes, there is. Once we get webpack 4 merged into 2.0 we are going to take a look at switching from |
I think we made a mistake when we added advanced proxy configuration in 1.x.
It's poor DX imo, and has caused numerous issues (I'm too lazy to search for them 😝).
I mean look at this monstrosity. Yuck!
I propose we support the simplest of configurations:
In the "advanced" case, we don't need to set
ssl
-- check forhttps://
overhttp://
. We don't need to setws
, check forws://
; etc.Other features (e.g. url rewrites) should never happen at the client layer because this doesn't translate to production (it's leaky domain logic).
Thoughts?
We can add some code to auto-migrate old usage and remove it in v3.
The text was updated successfully, but these errors were encountered: