Skip to content

Commit

Permalink
Update all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nrayburn-tech committed Jul 23, 2024
1 parent 46b6567 commit 5b3a188
Show file tree
Hide file tree
Showing 24 changed files with 804 additions and 61 deletions.
2 changes: 1 addition & 1 deletion examples/balancer/simple-balancer-with-websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

//
Expand Down
2 changes: 1 addition & 1 deletion examples/balancer/simple-balancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');
//
// A simple round-robin load balancing strategy.
Expand Down
2 changes: 1 addition & 1 deletion examples/http/basic-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const welcome = [
Expand Down
2 changes: 1 addition & 1 deletion examples/http/concurrent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const targetPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/custom-proxy-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

const httpProxy = require('../../lib');
const httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const targetPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/error-handling.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/forward-and-target-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/forward-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/latent-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
4 changes: 2 additions & 2 deletions examples/http/ntlm-authentication.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const httpProxy = require('../../lib');
const httpProxy = require('../../dist');
const Agent = require('agentkeepalive');
const { getPort } = require('../helpers/port');

Expand All @@ -8,7 +8,7 @@ const agent = new Agent({
maxFreeSockets: 10,
keepAliveMsecs: 1000,
timeout: 60000,
keepAliveTimeout: 30000, // free socket keepalive for 30 seconds
freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
});

const proxy = httpProxy.createProxy({
Expand Down
2 changes: 1 addition & 1 deletion examples/http/proxy-http-to-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const https = require('https'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
2 changes: 1 addition & 1 deletion examples/http/proxy-https-to-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
const http = require('http'),
path = require('path'),
fs = require('fs'),
httpProxy = require('../../lib'),
httpProxy = require('../../dist'),
fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures');
const { getPort } = require('../helpers/port');

Expand Down
2 changes: 1 addition & 1 deletion examples/http/proxy-https-to-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
const https = require('https'),
fs = require('fs'),
path = require('path'),
httpProxy = require('../../lib'),
httpProxy = require('../../dist'),
fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'),
httpsOpts = {
key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'),
Expand Down
2 changes: 1 addition & 1 deletion examples/http/reverse-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

const http = require('http'),
net = require('net'),
httpProxy = require('../../lib'),
httpProxy = require('../../dist'),
url = require('url');
const { getPort } = require('../helpers/port');

Expand Down
2 changes: 1 addition & 1 deletion examples/http/sse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib'),
httpProxy = require('../../dist'),
SSE = require('sse');
const { getPort } = require('../helpers/port');

Expand Down
2 changes: 1 addition & 1 deletion examples/http/standalone-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

const http = require('http'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
44 changes: 21 additions & 23 deletions examples/middleware/bodyDecoder-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

const http = require('http'),
connect = require('connect'),
request = require('request'),
queryString = require('querystring'),
bodyParser = require('body-parser'),
httpProxy = require('../../lib'),
httpProxy = require('../../dist'),
proxy = httpProxy.createProxy({});
const { getPort } = require('../helpers/port');

Expand Down Expand Up @@ -63,7 +62,7 @@ const targetPort = getPort();
//
const app = connect()
.use(bodyParser.json()) //json parser
.use(bodyParser.urlencoded()) //urlencoded parser
.use(bodyParser.urlencoded({extended: true})) //urlencoded parser
.use(function (req, res) {
// modify body here,
// eg: req.body = {a: 1}.
Expand Down Expand Up @@ -91,26 +90,25 @@ const app1 = connect()
});
http.createServer(app1).listen(targetPort, function () {
//request to 8013 to proxy
request.post(
{
//
url: 'http://127.0.0.1:' + proxyPort,
json: { content: 123, type: 'greeting from json request' },
},
function (err, res, data) {
console.log('return for json request:', err, data);
},
);
fetch('http://127.0.0.1:' + proxyPort, {
method: 'POST',
body: JSON.stringify({ content: 123, type: 'greeting from json request' }),
}).then((response) => {
return response.json();
}).then((data => {
console.log('return for json request:', data);
}))

// application/x-www-form-urlencoded request
request.post(
{
//
url: 'http://127.0.0.1:' + proxyPort,
form: { content: 123, type: 'greeting from urlencoded request' },
},
function (err, res, data) {
console.log('return for urlencoded request:', err, data);
},
);
fetch('http://127.0.0.1:' + proxyPort, {
method: 'POST',
body: new URLSearchParams({
content: 123,
type: 'greeting from urlencoded request',
}),
}).then((response) => {
return response.json();
}).then((data) => {
console.log('return for urlencoded request:', data);
})
});
29 changes: 15 additions & 14 deletions examples/middleware/gzip-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@
*/

const http = require('http'),
compression = require('compression'),
connect = require('connect'),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
const targetPort = getPort();
//
// Basic Connect App
//
connect
.createProxy(
connect.compress({
// Pass to connect.compress() the options
// that you need, just for show the example
// we use threshold to 1
threshold: 1,
}),
function (req, res) {
proxy.web(req, res);
},
)
.listen(proxyPort);
const app = connect();
app.use(
compression({
// Pass to compression() the options
// that you need, just for show the example
// we use threshold to 1
threshold: 1,
})
);
app.use(function (req, res) {
proxy.web(req, res);
});
http.createServer(app).listen(proxyPort);

//
// Basic Http Proxy Server
Expand Down
2 changes: 1 addition & 1 deletion examples/middleware/modifyResponse-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
const http = require('http'),
connect = require('connect'),
app = connect(),
httpProxy = require('../../lib');
httpProxy = require('../../dist');
const { getPort } = require('../helpers/port');

const proxyPort = getPort();
Expand Down
Loading

0 comments on commit 5b3a188

Please sign in to comment.