mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[examples] deleted this examples
This commit is contained in:
parent
cfd417de23
commit
bdeabb767a
@ -1,36 +0,0 @@
|
|||||||
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:'http://localhost:9000'}).listen(8000);
|
|
||||||
console.log("Proxy server listening on port 8000");
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
var httpProxy = require('../lib/http-proxy'),
|
|
||||||
http = require('http');
|
|
||||||
/*
|
|
||||||
* Create your proxy server
|
|
||||||
*/
|
|
||||||
var proxy = httpProxy.createProxyServer({target:'http://localhost:30404', ws:true});
|
|
||||||
|
|
||||||
var proxyServer = http.createServer(requestHandler);
|
|
||||||
|
|
||||||
function requestHandler(req, res) {
|
|
||||||
// Pass a callback to the web proxy method
|
|
||||||
// and catch the error there.
|
|
||||||
proxy.web(req, res, function (err) {
|
|
||||||
// Now you can get the err
|
|
||||||
// and handle it by your self
|
|
||||||
// if (err) throw err;
|
|
||||||
res.writeHead(502);
|
|
||||||
res.end("There was an error proxying your request");
|
|
||||||
});
|
|
||||||
|
|
||||||
// In a websocket request case
|
|
||||||
req.on('upgrade', function (req, socket, head) {
|
|
||||||
proxy.ws(req, socket, head, function (err) {
|
|
||||||
// Now you can get the err
|
|
||||||
// and handle it by your self
|
|
||||||
// if (err) throw err;
|
|
||||||
socket.close();
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Proxy server is listening on port 8000");
|
|
||||||
proxyServer.listen(8000)
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
var http = require('http'),
|
|
||||||
httpProxy = require('../lib/http-proxy');
|
|
||||||
|
|
||||||
//
|
|
||||||
// Target Http Server
|
|
||||||
//
|
|
||||||
http.createServer(function (req, res) {
|
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
||||||
res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
|
|
||||||
res.end();
|
|
||||||
}).listen(9000);
|
|
||||||
console.log("Web server listening on port 9000");
|
|
||||||
|
|
||||||
//
|
|
||||||
// Target Http Forwarding Server
|
|
||||||
//
|
|
||||||
http.createServer(function (req, res) {
|
|
||||||
console.log('Receiving forward for: ' + req.url);
|
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
||||||
res.write('request successfully forwarded to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2));
|
|
||||||
res.end();
|
|
||||||
}).listen(9001);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Basic Http Proxy Server
|
|
||||||
// Forward example: send requests without care about response
|
|
||||||
//
|
|
||||||
httpProxy.createServer({
|
|
||||||
target: 'http://localhost:9000',
|
|
||||||
forward: 'http://localhost:9001'
|
|
||||||
}).listen(8000)
|
|
||||||
console.log("Proxy server listening on port 8000");
|
|
||||||
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
var httpProxy = require('../lib/http-proxy'),
|
|
||||||
https = require('https');
|
|
||||||
/*
|
|
||||||
* Create your proxy server pointing to a secure domain
|
|
||||||
* Enable ssl validation
|
|
||||||
*/
|
|
||||||
var options = {
|
|
||||||
target : 'https://google.com',
|
|
||||||
agent : https.globalAgent,
|
|
||||||
headers: {host: 'google.com'}
|
|
||||||
};
|
|
||||||
|
|
||||||
var proxyServer = httpProxy.createProxyServer(options);
|
|
||||||
console.log("Proxy server listening on port 8000");
|
|
||||||
proxyServer.listen(8000);
|
|
||||||
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
var httpProxy = require('../lib/http-proxy');
|
|
||||||
/*
|
|
||||||
* Create your proxy server pointing to a secure domain
|
|
||||||
*/
|
|
||||||
var options = {
|
|
||||||
target:'https://google.com',
|
|
||||||
headers: {host: 'google.com'}
|
|
||||||
};
|
|
||||||
|
|
||||||
var proxyServer = httpProxy.createProxyServer(options);
|
|
||||||
console.log("Proxy server listening on port 8000");
|
|
||||||
proxyServer.listen(8000);
|
|
||||||
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
var http = require('http'),
|
|
||||||
httpProxy = require('../lib/http-proxy');
|
|
||||||
//
|
|
||||||
// Create your proxy server
|
|
||||||
//
|
|
||||||
console.log("Proxy server listening on port 8000");
|
|
||||||
httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Create your target server
|
|
||||||
//
|
|
||||||
console.log("Web server listening on port 9000");
|
|
||||||
http.createServer(function (req, res) {
|
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
||||||
res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
|
|
||||||
res.end();
|
|
||||||
}).listen(9000);
|
|
||||||
Loading…
x
Reference in New Issue
Block a user