Search code examples
javascriptnode.jshttp-proxy

Node JS http-proxy - issue with created URL


I created simple proxy server in node JS, it looks like this:

var httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});

//proxy config
app.all('/proxy/*', function (request, response) {
    "use strict";
    return proxy.web(request, response, {
    target: 'http://localhost:1234/'
    });
});

The problem I'm having is that it creates proxy URL from lets say sample request:

$http.get('/proxy/example')
        .success( function(res) {
          $scope.quote = res;
          alert($scope.quote);
          })

which looks like this:

localhost:1234/proxy/example

but I want it to create URL lookin like this:

localhost:1234/example

What am I doing wrong?

PS Sorry if question is not formatted properly or too easy - it's my first ask on stack


Solution

  • Don't do /proxy/example instead write only example

       $http.get('example')
        .success( function(res) {
          $scope.quote = res;
          alert($scope.quote);
          })