Skip to content

Commit

Permalink
Merge pull request meteor#120 from meteor/avital-websockets
Browse files Browse the repository at this point in the history
Proxy websocket requests into inner web server
n1mmy committed May 1, 2012
2 parents 54f70c2 + 2ca10b1 commit 8913a2b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/meteor/run.js
Original file line number Diff line number Diff line change
@@ -96,6 +96,25 @@ var start_proxy = function (outer_port, inner_port, callback) {
}
});

// Proxy websocket requests using same buffering logic as for regular HTTP requests
p.on('upgrade', function(req, socket, head) {
if (Status.listening) {
// server is listening. things are hunky dory!
p.proxy.proxyWebSocketRequest(req, socket, head, {
host: '127.0.0.1', port: inner_port
});
} else {
// Not listening yet. Queue up request.
var buffer = httpProxy.buffer(req);
request_queue.push(function () {
p.proxy.proxyWebSocketRequest(req, socket, head, {
host: '127.0.0.1', port: inner_port,
buffer: buffer
});
});
}
});

p.on('error', function (err) {
if (err.code == 'EADDRINUSE') {
process.stderr.write("Can't listen on port " + outer_port

0 comments on commit 8913a2b

Please sign in to comment.