how to make a proxy server node.js
var fs = require('fs');
var http = require('http'),
var https = require('https'),
var httpProxy = require('http-proxy');
isHttps = true;
var options = {
ssl: {
key: fs.readFileSync('valid-key.pem'),
cert: fs.readFileSync('valid-cert.pem')
}
};
proxyServer = proxy.createProxyServer({target:'http://127.0.0.1:9000'});
proxyServer.listen(8000);
if (isHttps){
server = https.createServer(options.ssl, function(req, res) {
console.log(“https request”);
proxyServer.web(req, res, { target: req.url });
proxyServer.on('error', function(e) {
console.log("Error in proxy call");
});
proxyServer.listen(443);
});
}else{
server = http.createServer(function (req, res) {
console.log(req.url);
proxyServer.web(req, res, { target: req.url });
proxyServer.on('error', function(e) {
console.log("Error in proxy call");
});
});
}
server.listen(9000);
Also in JavaScript:
- js object destructuring with defaults
- change style on click react
- foreach break js
- javascript ellipsis
- swap elements in array javascript
- javascript text to clipboard
- use .map to count length of each element in an array
- javascript render jsx element x many times
- angular npx
- nextjs reportWebVitals function
- js access sql database on server
- adonisjs column default value
- how to call javascript method using selectlist on change in vf page
- vue redirect to route
- input radio trigger select jquery
- cordova js how to load local file in subdir
- capitalise first letter js
- if statement javascript
- how to select a class and then change the children of that class with javascript
- javascript context color
- math random equitative js
- expressjs cheat sheet
- javascript array push method
- jquery detect nav tab change event