-
Notifications
You must be signed in to change notification settings - Fork 2k
POST fails/hangs examples to restream also not working #1279
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
Comments
Are there any updates on this? Would downgrading to an earlier version help? If so does anyone know how to find out what version the example was written against? I'm getting a |
@isawk any chance to get this fixed, I'm having the same issue, see above links. Thanks. |
I resolved issue with the following code:
Am using nestjs however this should work regardless of your implementation.
take note of this.apiProxyServer.once('proxyReq', appears proxy runs
multiple times, i found this once function whiles inspecting code base
@ALL("/end-points")
proxy(@Req() request, @res() response) {
this.apiProxyServer.once('proxyReq', function (proxyReq, req, res, options)
{
console.debug("Proxying request");
let bodyData;
if (!req.body || !Object.keys(req.body).length) {
return;
}
switch( proxyReq.getHeader('Content-Type') ){
case "application/json":
case "application/json; charset=UTF-8":bodyData = JSON.stringify(req.body);
break;
case "application/x-www-form-urlencoded":bodyData = querystring.stringify(
req.body);break;
default: console.debug("unable to process content type ", proxyReq.getHeader
('Content-Type') );
}
if (bodyData) {
console.debug("request has body data, proxying");
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
});
this.apiProxyServer.web(request, response);
}
}
…On Tue, Sep 25, 2018 at 6:31 PM Loreto Parisi ***@***.***> wrote:
@isawk <https://github.com/isawk> any chance to get this fixed, I'm
having the same issue, see above links. Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1279 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AUDbqSCEFJwQXKaXyxD3vg6wRtbFHt90ks5uelppgaJpZM4VILNo>
.
--
Kwasi Gyasi-Agyei
I am part of an *EDGED* crowd
*Mobile* +27 (81) 466 4488
*Email* [email protected]
*Skype* kwasi.gyasiagyei
*Web* http://edged.agency
|
@isawk thanks a lot! This is the only way it worked 👍 💯 🔢 🥇 proxy.once('proxyReq', function (proxyReq, req, res, options) { //restream
let bodyData;
if (!req.body || !Object.keys(req.body).length) {
return;
}
switch( proxyReq.getHeader('Content-Type') ){
case "application/json":
case "application/json; charset=UTF-8":
bodyData = JSON.stringify(req.body);
break;
case "application/x-www-form-urlencoded":
bodyData = querystring.stringify(req.body);
break;
default:
}
if (bodyData) {
console.debug("---[proxyReq]----", bodyData);
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
proxyReq.end();
}
});
proxy.on('proxyRes', function (proxyRes, req, res) {
modifyResponse(res, proxyRes, function (response) {
console.log("----[proxyRes]---->", response)
// modify response eventually
return response; // return value can be a promise
});
});
proxy.web(req, res, {
// url string to be parsed with the url module
target: target_uri,
// true/false, Default: false - changes the origin of the host header to the target URL
changeOrigin: true,
// true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request
ignorePath: true
}); |
same here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example (https://github.com/nodejitsu/node-http-proxy/blob/master/examples/middleware/bodyDecoder-middleware.js) to restream body for 1.17.0 not working in order to send data with post method
Node: v8.11.2
node-http-proxy: 1.17.0
The text was updated successfully, but these errors were encountered: