Skip to content

Commit 5b3a188

Browse files
committed
Update all examples
1 parent 46b6567 commit 5b3a188

24 files changed

+804
-61
lines changed

examples/balancer/simple-balancer-with-websockets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
//

examples/balancer/simple-balancer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030
//
3131
// A simple round-robin load balancing strategy.

examples/http/basic-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const welcome = [

examples/http/concurrent-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const targetPort = getPort();

examples/http/custom-proxy-error.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
*/
2626

27-
const httpProxy = require('../../lib');
27+
const httpProxy = require('../../dist');
2828
const { getPort } = require('../helpers/port');
2929

3030
const targetPort = getPort();

examples/http/error-handling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/http/forward-and-target-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/http/forward-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/http/latent-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/http/ntlm-authentication.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const httpProxy = require('../../lib');
1+
const httpProxy = require('../../dist');
22
const Agent = require('agentkeepalive');
33
const { getPort } = require('../helpers/port');
44

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

1414
const proxy = httpProxy.createProxy({

examples/http/proxy-http-to-https.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const https = require('https'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/http/proxy-https-to-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
const http = require('http'),
2828
path = require('path'),
2929
fs = require('fs'),
30-
httpProxy = require('../../lib'),
30+
httpProxy = require('../../dist'),
3131
fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures');
3232
const { getPort } = require('../helpers/port');
3333

examples/http/proxy-https-to-https.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
const https = require('https'),
2828
fs = require('fs'),
2929
path = require('path'),
30-
httpProxy = require('../../lib'),
30+
httpProxy = require('../../dist'),
3131
fixturesDir = path.join(__dirname, '..', '..', 'test', 'fixtures'),
3232
httpsOpts = {
3333
key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'),

examples/http/reverse-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
const http = require('http'),
2525
net = require('net'),
26-
httpProxy = require('../../lib'),
26+
httpProxy = require('../../dist'),
2727
url = require('url');
2828
const { getPort } = require('../helpers/port');
2929

examples/http/sse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib'),
28+
httpProxy = require('../../dist'),
2929
SSE = require('sse');
3030
const { getPort } = require('../helpers/port');
3131

examples/http/standalone-proxy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
const http = require('http'),
28-
httpProxy = require('../../lib');
28+
httpProxy = require('../../dist');
2929
const { getPort } = require('../helpers/port');
3030

3131
const proxyPort = getPort();

examples/middleware/bodyDecoder-middleware.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626

2727
const http = require('http'),
2828
connect = require('connect'),
29-
request = require('request'),
3029
queryString = require('querystring'),
3130
bodyParser = require('body-parser'),
32-
httpProxy = require('../../lib'),
31+
httpProxy = require('../../dist'),
3332
proxy = httpProxy.createProxy({});
3433
const { getPort } = require('../helpers/port');
3534

@@ -63,7 +62,7 @@ const targetPort = getPort();
6362
//
6463
const app = connect()
6564
.use(bodyParser.json()) //json parser
66-
.use(bodyParser.urlencoded()) //urlencoded parser
65+
.use(bodyParser.urlencoded({extended: true})) //urlencoded parser
6766
.use(function (req, res) {
6867
// modify body here,
6968
// eg: req.body = {a: 1}.
@@ -91,26 +90,25 @@ const app1 = connect()
9190
});
9291
http.createServer(app1).listen(targetPort, function () {
9392
//request to 8013 to proxy
94-
request.post(
95-
{
96-
//
97-
url: 'http://127.0.0.1:' + proxyPort,
98-
json: { content: 123, type: 'greeting from json request' },
99-
},
100-
function (err, res, data) {
101-
console.log('return for json request:', err, data);
102-
},
103-
);
93+
fetch('http://127.0.0.1:' + proxyPort, {
94+
method: 'POST',
95+
body: JSON.stringify({ content: 123, type: 'greeting from json request' }),
96+
}).then((response) => {
97+
return response.json();
98+
}).then((data => {
99+
console.log('return for json request:', data);
100+
}))
104101

105102
// application/x-www-form-urlencoded request
106-
request.post(
107-
{
108-
//
109-
url: 'http://127.0.0.1:' + proxyPort,
110-
form: { content: 123, type: 'greeting from urlencoded request' },
111-
},
112-
function (err, res, data) {
113-
console.log('return for urlencoded request:', err, data);
114-
},
115-
);
103+
fetch('http://127.0.0.1:' + proxyPort, {
104+
method: 'POST',
105+
body: new URLSearchParams({
106+
content: 123,
107+
type: 'greeting from urlencoded request',
108+
}),
109+
}).then((response) => {
110+
return response.json();
111+
}).then((data) => {
112+
console.log('return for urlencoded request:', data);
113+
})
116114
});

examples/middleware/gzip-middleware.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,29 @@
2525
*/
2626

2727
const http = require('http'),
28+
compression = require('compression'),
2829
connect = require('connect'),
29-
httpProxy = require('../../lib');
30+
httpProxy = require('../../dist');
3031
const { getPort } = require('../helpers/port');
3132

3233
const proxyPort = getPort();
3334
const targetPort = getPort();
3435
//
3536
// Basic Connect App
3637
//
37-
connect
38-
.createProxy(
39-
connect.compress({
40-
// Pass to connect.compress() the options
41-
// that you need, just for show the example
42-
// we use threshold to 1
43-
threshold: 1,
44-
}),
45-
function (req, res) {
46-
proxy.web(req, res);
47-
},
48-
)
49-
.listen(proxyPort);
38+
const app = connect();
39+
app.use(
40+
compression({
41+
// Pass to compression() the options
42+
// that you need, just for show the example
43+
// we use threshold to 1
44+
threshold: 1,
45+
})
46+
);
47+
app.use(function (req, res) {
48+
proxy.web(req, res);
49+
});
50+
http.createServer(app).listen(proxyPort);
5051

5152
//
5253
// Basic Http Proxy Server

examples/middleware/modifyResponse-middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
const http = require('http'),
2828
connect = require('connect'),
2929
app = connect(),
30-
httpProxy = require('../../lib');
30+
httpProxy = require('../../dist');
3131
const { getPort } = require('../helpers/port');
3232

3333
const proxyPort = getPort();

0 commit comments

Comments
 (0)