Created
December 7, 2019 19:22
-
-
Save kakopappa/d5fd7ede369e4a3d5c98c0a3436bfd8c to your computer and use it in GitHub Desktop.
nodejs proxy for IIS Express
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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