Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Proxy off a specific URI? #403

Closed
occasl opened this Issue · 1 comment

1 participant

@occasl

I'm using restify for several service URI's but I would like one particular service URI to be forwarded to a different host allowing my service to act as a proxy for the results from that host.

e.g.,

http://myservice/solr-suggest?q=lou&bunchOfQueryParams=more --> http://realservice/solr-suggest?q=lou&bunchOfQueryParams=more

Here's the code I have tried to do this:

    var restify = require('restify'),
          server = restify.createServer({...});

    server.get('/solr-suggest', proxy.solrSuggest);
    server.listen(80, '127.0.0.1', function () {
        console.log('%s listening at %s', server.name, server.url);
    });

   // Here's the supporting call that I'm exporting for the above call
   var http = require('http'),
        httpProxy = require('http-proxy'),
        host = 'realservice.domain.com',
        port = 80;

    var proxy = new httpProxy.RoutingProxy();

    exports.solrSuggest = function (req, res) {
        httpProxy.createServer(function (req, res, proxy) {
          proxy.proxyRequest(req, res, {
            host: host,
            port: port
          });
        }).listen(80);
    };

Is it possible to do this within an existing service like this?

@occasl

Chalk it up to a late night, but all that was required is to remove the create server since I already did that before. The result was this:

    var http = require('http'),
        httpProxy = require('http-proxy'),
        host = 'realservice.domain.com',
        port = 80;

    var proxy = new httpProxy.RoutingProxy();

    exports.solrSuggest= function (req, res) {
        proxy.proxyRequest(req, res, {
            host: host,
            port: port
        });
    };
@occasl occasl closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.