http GET request is not proxied
See original GitHub issueExpected behavior
GET request should be proxied properly
Actual behavior
GET request is totally ignored by the http-proxy-middleware while POST and DELETE request to the same target server work as expected
Setup
- http-proxy-middleware: 0.17.4
- server: browser-sync 2.18.11
- other relevant modules
proxy middleware configuration
import config from '../webpack.config.dev';
const bundler = webpack(config);
const proxy = require('http-proxy-middleware');
const authenticationProxy = proxy('/authentication', {
target: 'https://remote123.com/authentication-web/authentication',
secure: false,
pathRewrite: {
'^/authentication' : ''
}
});
const TACProxy = proxy('/terms-and-conditions', {
target: 'https://remote456.com/info-web/terms-and-conditions',
secure: false,
pathRewrite: {
'^/terms-and-conditions' : ''
}
});
const infoProxy = proxy('/info', {
target: 'https://remote456.com/info-web/info',
secure: false
pathRewrite: {
'^/info' : ''
}
});
server mounting
browserSync({
port: 5200,
ui: {
port: 5201 // port where browsersync admin site will be avaialble
},
//cors: true,
server: {
baseDir: 'src', // base folder to serve
middleware: [
historyApiFallback(),
webpackDevMiddleware(bundler, {
publicPath: 'http://localhost:5200/',
noInfo: true
}),
webpackHotMiddleware(bundler),
// proxy for backend
authenticationProxy, //this works, POST method
TACProxy, //this works, DELETE method
infoProxy // GET method NOT working, but POST works! same target host as the one above
]
},
files: [
'src/*.html'
]
});
As the code snippet shown above, the TACProxy
and infoProxy
have same target host, remote456.com
. If I send POST request to them, both proxies works; but GET request is always ignored by the proxy.
The response of GET request is suppose to be a json, but it’s actually the html that should be rendered by the browser. It’s like
<!DOCTYPE html><html lang="en"><head></head><body><div id="app"></div><script type="text/javascript" src="/main.bundle.js"></script></body></html>
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Node http requests not going through proxy - Stack Overflow
This time Node attempted to send the request directly to the target server. This resulted in the proxy blocking the request completely. The...
Read more >6.5. Tricky Things About Proxy Requests - HTTP - O'Reilly
Tricky Things About Proxy Requests This section explains some of the tricky and much misunderstood aspects of proxy server requests, including: How the...
Read more >Make HTTP requests with the HttpClient - .NET - Microsoft Learn
To make an HTTP GET request, given an HttpClient and a URI, ... To specify that no proxy should be used, set the...
Read more >HTTP/1.1: Header Field Definitions
If no Accept-Encoding field is present in a request, the server MAY assume that the client will accept any content coding. In this...
Read more >How to proxy HTTP requests in Angular | by Maria Korneeva
Though the usual CORS error looks slightly different, the fact is — your backend does not like receiving requests from unmatching origins (which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After a loooot of attempts, it suddenly works when I move my proxies settings in front of
webpackDevMiddleware
in thebrowserSync
server mounting.Like this,
I’ve also modified my
'/info'
api method call from aGET
to aPOST
, and as soon as I do this (without any modification on the proxy configuration) it works (meaning the request is proxied as expected)