Node.js node-http-proxy, url-encoded data proxy

I am new to Node.js and am struggling to figure out how to create a simple proxy for a given route / url.

I am trying to avoid cross-domain issues for the javascript framework by using a proxy with my Node.js (with an express server). I am using a module node-http-proxy

, but I am having a problem where request.body is always JSON. I need to send url encoded data, not JSON, to the register server endpoint. So even if I send url-encoded data as the request body to the proxy, the proxy then sends the JSON data as the request body to the registrar.

I tried converting the body to url encoded string in the proxy, but then it adds even more quirky quote character to the beginning of the body. One double quote.

Thanks for the help. Here's my route:

this.match('/proxy/logging', function(req, res, next){
    req.url = build.logging_url.path;
    req.body = require('querystring').stringify(req.body);
    req.headers['content-length'] = req.body.length;
    proxy.proxyRequest(req, res, {
      host: build.logging_url.host
      , port: build.logging_url.port
    });
}, { via: 'POST' });

      

and my ajax call, in jquery:

$.ajax({
    type: 'POST',
    url: POSTURL,
    data: {foobar : "foobar"},
    success: on_post_success,
    error: on_post_error
});

      

+3
node.js node-http-proxy


source to share


No one has answered this question yet

Check out similar questions:

891
How is an HTTP POST request made in node.js?
736
How do I make Base64 encoding in node.js?
581
How do I handle POST data in Node.js?
44
Sending data via POST request from node.js server to node.js server
22
Node.js http-proxy drops websocket requests
12
Node.js HTTP: "end" request is never called
4
Node Prerender / PhantomJS + http-proxy doesn't work with websocket
2
http service in angular message send data as request body key with no value
1
Extracting JSON data from a request in a node
0
Change request body as JSON with Node.js proxy middleware



All Articles
Loading...
X
Show
Funny
Dev
Pics