Skip to content

Instantly share code, notes, and snippets.

@kakopappa
Created December 7, 2019 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakopappa/d5fd7ede369e4a3d5c98c0a3436bfd8c to your computer and use it in GitHub Desktop.
Save kakopappa/d5fd7ede369e4a3d5c98c0a3436bfd8c to your computer and use it in GitHub Desktop.
nodejs proxy for IIS Express
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createProxyServer({});
// To modify the proxy connection before data is sent, you can listen
// for the 'proxyReq' event. When the event is fired, you will receive
// the following arguments:
// (http.ClientRequest proxyReq, http.IncomingMessage req,
// http.ServerResponse res, Object options). This mechanism is useful when
// you need to modify the proxy request before the proxy connection
// is made to the target.
//
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');
});
var server = http.createServer(function(req, res) {
// You can define here your custom logic to handle the request
// and then proxy the request.
proxy.web(req, res, {
target: 'http://localhost:53990'
});
});
console.log("listening on port 9000")
server.listen(9000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment