1

I'd like to have multiple nodejs applications all listening on different ports proxied to a URL on my local machine.

An example would be

localhost:3000 -> mysite.dev localhost:3030 -> mysite.dev/api

It would make developing locally match my production setup and help immensely with my stateless authentication setep. I thought hotel was going to be the solution I wanted, but it doesn't do exactly what I'm looking for.

If possible I'd like to avoid using nginx locally.

1 Answer 1

1

You can try http-proxy module and you can specify proxy as

var http = require('http'),
    httpProxy = require('http-proxy');
//
// Create your proxy server and set the target in the options.
//
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); // See (†)

//
// Create your target server
//
http.createServer(function (req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
  res.end();
}).listen(9000);

they have nice docs available here https://github.com/nodejitsu/node-http-proxy

Sign up to request clarification or add additional context in comments.

2 Comments

That's great, thank you. This is just what I'm looking for.
Could you put up an example that answers the question which includes 2 separate proxies on port 80 separated by the URI?

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.