Skip to content

Commit

Permalink
Attach event listener to the http(s) server.
Browse files Browse the repository at this point in the history
Expose `upgrade` proxy handler on foxy `app` instance as `handleUpgrade`
Attach `upgrade` listener in CLI server creation.

Issue #2
  • Loading branch information
simshanith committed Apr 25, 2015
1 parent 7e063b3 commit 42ec2ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ function handleCli (cli) {
*/
function getServer (scheme, app) {

var server;

if (scheme === "https") {

return https.createServer({
server = https.createServer({
key: fs.readFileSync(path.resolve(__dirname, "test/fixtures/certs/server.key")),
cert: fs.readFileSync(path.resolve(__dirname, "test/fixtures/certs/server.cert"))
}, app);
}

return http.createServer(app);
server = http.createServer(app);
server.on("upgrade", app.handleUpgrade);

return server;
}
4 changes: 2 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ module.exports = function (config) {
* Handle `upgrade` event to proxy WebSockets
* https://github.com/nodejitsu/node-http-proxy#proxying-websockets
*/
app.on("upgrade", function (req, socket, head) {
app.handleUpgrade = function (req, socket, head) {
proxy.ws(req, socket, head);
});
};

/**
* Proxy errors out to user errHandler
Expand Down

0 comments on commit 42ec2ab

Please sign in to comment.