-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] added concurrent proxy example
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var http = require('http'), | ||
httpProxy = require('../lib/http-proxy'); | ||
|
||
var connections = [], | ||
go; | ||
|
||
|
||
// | ||
// Target Http Server | ||
// | ||
// to check apparent problems with concurrent connections | ||
// make a server which only responds when there is a given nubmer on connections | ||
// | ||
http.createServer(function (req, res) { | ||
connections.push(function () { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); | ||
res.end(); | ||
}); | ||
|
||
process.stdout.write(connections.length + ', '); | ||
|
||
if (connections.length > 10 || go) { | ||
go = true; | ||
while (connections.length) { | ||
connections.shift()(); | ||
} | ||
} | ||
}).listen(9000); | ||
console.log("Web server listening on port 9000"); | ||
|
||
// | ||
// Basic Http Proxy Server | ||
// | ||
httpProxy.createProxyServer({target:'https://localhost:9000'}).listen(8000); | ||
console.log("Proxy server listening on port 8000"); |