Skip to content

Commit 8fc8d96

Browse files
committed
[examples] Updated examples to v0.7.x API.
1 parent 24ef919 commit 8fc8d96

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

examples/websocket/latent-websocket-proxy.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ socket.on('connection', function (client) {
6767
//
6868
// Setup our server to proxy standard HTTP requests
6969
//
70-
var proxy = new httpProxy.HttpProxy();
71-
var proxyServer = http.createServer(function (req, res) {
72-
proxy.proxyRequest(req, res, {
70+
var proxy = new httpProxy.HttpProxy({
71+
target: {
7372
host: 'localhost',
7473
port: 8080
75-
})
74+
}
75+
});
76+
var proxyServer = http.createServer(function (req, res) {
77+
proxy.proxyRequest(req, res);
7678
});
7779

7880
//
@@ -83,11 +85,7 @@ proxyServer.on('upgrade', function (req, socket, head) {
8385
var buffer = httpProxy.buffer(socket);
8486

8587
setTimeout(function () {
86-
proxy.proxyWebSocketRequest(req, socket, head, {
87-
port: 8080,
88-
host: 'localhost',
89-
buffer: buffer
90-
});
88+
proxy.proxyWebSocketRequest(req, socket, head, buffer);
9189
}, 1000);
9290
});
9391

examples/websocket/standalone-websocket-proxy.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,22 @@ socket.on('connection', function (client) {
6767
//
6868
// Setup our server to proxy standard HTTP requests
6969
//
70-
var proxy = new httpProxy.HttpProxy();
71-
var proxyServer = http.createServer(function (req, res) {
72-
proxy.proxyRequest(req, res, {
70+
var proxy = new httpProxy.HttpProxy({
71+
target: {
7372
host: 'localhost',
7473
port: 8080
75-
})
74+
}
75+
});
76+
var proxyServer = http.createServer(function (req, res) {
77+
proxy.proxyRequest(req, res);
7678
});
7779

7880
//
7981
// Listen to the `upgrade` event and proxy the
8082
// WebSocket requests as well.
8183
//
8284
proxyServer.on('upgrade', function (req, socket, head) {
83-
proxy.proxyWebSocketRequest(req, socket, head, {
84-
port: 8080,
85-
host: 'localhost'
86-
});
85+
proxy.proxyWebSocketRequest(req, socket, head);
8786
});
8887

8988
proxyServer.listen(8081);

0 commit comments

Comments
 (0)