Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle upgrade event to proxy WebSockets #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
10 changes: 9 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ module.exports = function (config) {
// We are fine with this, considering this is a development tool, not to be used in production. :)
});

/**
* Handle `upgrade` event to proxy WebSockets
* https://github.com/nodejitsu/node-http-proxy#proxying-websockets
*/
app.handleUpgrade = function (req, socket, head) {
proxy.ws(req, socket, head);
};

/**
* Proxy errors out to user errHandler
*/
Expand Down Expand Up @@ -96,4 +104,4 @@ module.exports = function (config) {
}

return app;
};
};