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


source to share





All Articles