Giter VIP home page Giter VIP logo

Comments (11)

gstroup avatar gstroup commented on May 18, 2024 5

Spent half the day fighting with my corporate proxy, until I found this. Thank you! Works perfectly.

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024 3

Glad to hear this thread helped you out.

I've added a corporate proxy configuration example to the recipes:
https://github.com/chimurai/http-proxy-middleware/blob/master/recipes/corporate-proxy.md

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024 1

Think I found the pathRewrite issue...

I pushed a patch into this branch:
https://github.com/chimurai/http-proxy-middleware/tree/proxy-agent-path-rewrite-fix

Would be great if you could test this patch, before merging the patch.

from http-proxy-middleware.

sinedied avatar sinedied commented on May 18, 2024 1

I just tested, it works!!

Good job, and thanks for the quick fix 👍

from http-proxy-middleware.

gstroup avatar gstroup commented on May 18, 2024 1

Perfect. Thanks!

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024

Hi,

I've never used the toProxy option before...
http-proxy-middleware is just a small middleware wrapper around http-proxy.

From the http-proxy's code and tests I noticed toProxy is expecting a boolean. Perhaps changing it to a boolean wil solve the issue.

http-proxy code comment:
https://github.com/nodejitsu/node-http-proxy/blob/76051032e7dcea522a691e88ffbc2f8d03f1365c/lib/http-proxy.js#L40

http-proxy test case:
https://github.com/nodejitsu/node-http-proxy/blob/76051032e7dcea522a691e88ffbc2f8d03f1365c/test/lib-http-proxy-common-test.js#L238

Interesting idea.
Could you clarify or give an example on how http_proxy and https_proxy environment variables could be used and configured automatically?

from http-proxy-middleware.

sinedied avatar sinedied commented on May 18, 2024

I already tried using true as a value for toProxy, still no luck.

I'll explain what I would like to achieve:

  • I have browserSync with a dev server setup for my web app
  • The backend endpoint should be located at the /api URI, with the same host as the web app.
    For this I use your module, to redirect /api to http://other_host.com/api, another host with the backend (integration or production server).
  • When I have to use a corporate proxy for internet access, I would like this setup to work: requests to http://other_host.com/api should go through the proxy.

My problem is currently the last point, and it would be where the http_proxy environment variables should be used (to redirect or not through the proxy). Even manually, I am currently unable to make the last point work, I know it should be possible but I don't know how :-/

from http-proxy-middleware.

sinedied avatar sinedied commented on May 18, 2024

I looked at the issues in node-http-proxy and found a possible solution to my issue: http-party/node-http-proxy#832

Seems like it could be fixed in code and not in the config (example for https with env variable):

var HttpsProxyAgent = require('https-proxy-agent');
var proxyServer = process.env.http_proxy;

var proxy = httpProxy.createProxyServer({
agent: new HttpsProxyAgent(proxyServer)
});

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024

Interesting. If that solves the issue, it probably will work as well when you provide agent to http-proxy-middleware as such:

var proxyMiddleware = require('http-proxy-middleware');
var HttpsProxyAgent = require('https-proxy-agent');
var proxyServer     = process.env.http_proxy;

var proxy = proxyMiddleware({
  context: '/api',
  options: {
    pathRewrite: { '^/api' : '' },
    target: 'http://api.stuff.com',
    changeOrigin: true,
    agent: new HttpsProxyAgent(proxyServer)
})

from http-proxy-middleware.

sinedied avatar sinedied commented on May 18, 2024

That's what I'm currently doing, with added env.http_proxy detection:

function setupCorporateProxy(options) {
  var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
  if (proxyServer) {
    options.agent = new HttpProxyAgent(proxyServer);
    gutil.log(gutil.colors.cyan('Using corporate proxy server: ' + proxyServer));
  }

  return options;
}

The request seems to be sent to the proxy just fine, but now the URL rewriting is skipped for the request sent to the proxy: according to my config, the /api should be removed when sent to the proxy but it is not :-/

from http-proxy-middleware.

chimurai avatar chimurai commented on May 18, 2024

Np. Thanks for reporting the issue!

Just pushed v0.8.1 with the fix.

from http-proxy-middleware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.