0

I need a HTTP-Proxy to access an external API while I'm developing to get around cross domain security restrictions.

I found some example code here: http://nthloop.com/blog/local-dev-with-nodejs-proxy/

Which looks like exactly what I'm looking for, unfortunately when I've tried using it I get timed out trying to hit my local files.

No error in the console either.

Specifically the issue is from this section of code:

.use(function(req, res) {
  if (req.url.indexOf(endpoint.prefix) != -1) {
    proxy.proxyRequest(req, res, endpoint);
  }
})

My local server seems to get stuck in a loop here with no response, there are no errors in my console.

Charles http sniffer shows a request is made, but no response is received.

Any idea how I can get this working?

1 Answer 1

1

Local server is getting stuck because the middleware does not delegate handling of cases when the if condition fails further down the middleware chain :

The following should solve the problem :


  .use(function(req, res, next) {
    if (req.url.indexOf(endpoint.prefix) === 0) {
      proxy.proxyRequest(req, res, endpoint);
    } else next();
  })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.