Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Proxy Settings with Nodejs for localhost

I have a nodejs application running using express on my localhost. I use bootstrap as well. The problem is that at my workplace I have to use proxy settings. Once I type localhost:3000 it gets redirected to an IP address that does not run. If I remove the proxy settings from Google Chrome localhost:3000 works some of the times but without the bootstrap styling.

I am also using routes to direct different urls to the corresponding ejs pages:

router.get('/', function(req, res, next) {  
  res.render('index', {});
});

The index.ejs file has a URL pointing to the bootstrap css online remote file.

Is there a way to have it running using the proxy as well.

Thank you in advance :)

like image 485
Prolog Programmer Avatar asked Aug 23 '26 19:08

Prolog Programmer


1 Answers

Use module http-proxy

npm install http-proxy

It is then possible to proxy requests by calling these functions

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

//
// Create your proxy server and set the target in the options.
//
httpProxy.createProxyServer({ target:'http://192.168.126.128:8080' }).listen(9000);

For more information visit https://github.com/nodejitsu/node-http-proxy

like image 69
I_Al-thamary Avatar answered Aug 26 '26 08:08

I_Al-thamary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!