Comments (11)
Spent half the day fighting with my corporate proxy, until I found this. Thank you! Works perfectly.
from http-proxy-middleware.
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.
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.
I just tested, it works!!
Good job, and thanks for the quick fix 👍
from http-proxy-middleware.
Perfect. Thanks!
from http-proxy-middleware.
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.
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
tohttp://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.
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.
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.
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.
Np. Thanks for reporting the issue!
Just pushed v0.8.1 with the fix.
from http-proxy-middleware.
Related Issues (20)
- POST request looses body HOT 2
- Unable to output console.log and my plugin is not running HOT 4
- v3 Next.js API Route Websocket multiple requests HOT 3
- Shadow/mirror requests HOT 2
- Express multipart/form-data multer files HOT 1
- Memory leak in function `responseInterceptor` of file `handlers/response-interceptor.ts` HOT 1
- Next.js App Router can't handle proxied requests HOT 16
- Filter example in README wrong. HOT 1
- Cannot override options in the `onProxyReq` method. HOT 1
- websocket messages interception & manipulation
- Intercept HTTP(s) calls and modify request "paths" on the fly HOT 1
- Issue obtaining body and updating it as part of proxy HOT 3
- Proxy request fails due to bodyParser HOT 1
- Fails to proxy from localhost to localhost HOT 2
- Too many subscriptions to Server.close event cause a OOM? HOT 4
- TS type compatibility HOT 4
- ERR_HTTP_HEADERS_SENT from onProxyReq with https-proxy-agent HOT 2
- Proxy to another proxy HOT 1
- Security Vulnerability in Dependency | follow-redirects HOT 2
- "Invalid context" error message is unhelpful when mixing paths with globs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http-proxy-middleware.