Node-http-proxy: EHOSTUNREACH err?

Created on 22 Jan 2016  路  2Comments  路  Source: http-party/node-http-proxy

Hi, I'm trying to use node-http-proxy to proxy to my app's api if the request url contains a specific path, and if not, just serve up static content from a local file server...

var LOCAL = 'localhost:' + process.env.PORT
var STATIC = 'localhost:' + process.env.STATIC

var proxy = httpProxy.createProxyServer({
    xfwd: true
    , secure: false // ignore ssl certs
    , ws: true
})

var server = http.createServer(function (req, res) {
    var url = req.url
    if (req.url.indexOf('/v1') > -1) {
            url = HOST + req.url
            process.stdout.write('PROXYING '
                                + req.method
                                + ':' + req.url
                                + ' -> ' + url + '\n')

            proxy.web(req, res, {
                target: HOST
            })
        }
    } else {
        url = STATIC + req.url
        process.stdout.write('SERVING '
                            + req.method
                            + ':' + req.url
                            + ' -> ' + url + '\n')

        proxy.web(req, res, {
            target: STATIC
            , toProxy: true
        })
    }
})

I have http-server running on 9001 and serving from build: http-server ./build -p 9001 -c-1.

If I hit localhost:9000 I get this error:

node_modules/http-proxy/lib/http-proxy/index.js:119
    throw err;
    ^

Error: connect EHOSTUNREACH 0.0.35.41:80 - Local (10.0.1.3:49510)
    at Object.exports._errnoException (util.js:874:11)
    at exports._exceptionWithHostPort (util.js:897:20)
    at connect (net.js:841:14)
    at net.js:984:7
    at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:63:16)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:82:10)

I haven't been able to find anything related to this error inside the issues. Suggestions? I really have no idea what could be causing this except for the obvious stuff like localhost issues (tried 127.0.0.1, and modifying /etc/hosts to point to something like my.dev).

Most helpful comment

After futzing around for an hour I finally figured out that target: http:// is the secret sauce. It appears without a protocol something coughs.

All 2 comments

After futzing around for an hour I finally figured out that target: http:// is the secret sauce. It appears without a protocol something coughs.

This issue could be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damianchojna picture damianchojna  路  5Comments

isawk picture isawk  路  5Comments

guillaume-at-palo picture guillaume-at-palo  路  4Comments

sisyphsu picture sisyphsu  路  3Comments

jsmylnycky picture jsmylnycky  路  3Comments