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

Add websocket support #21

Merged
merged 2 commits into from
Apr 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node

var os = require('os'),
proxy = require('http-proxy'),
http = require('http'),
httpProxy = require('http-proxy'),
pkg = require('./package');

var exit = function() {
Expand Down Expand Up @@ -51,12 +52,24 @@ Object.keys(interfaces).forEach(function(name) {
});
});

proxy.createProxyServer({
target: protocolPrefix + host + ':' + port,
var proxy = new httpProxy.createProxyServer({
target: {
host: host,
port: port,
protocol: protocolPrefix
},
secure: false,
changeOrigin: true,
xfwd: true
}).listen(proxyPort, function() {
});
var proxyServer = http.createServer(function (req, res) {
proxy.web(req, res);
});
proxyServer.on('upgrade', function (req, socket, head) {
proxy.ws(req, socket, head);
});

proxyServer.listen(proxyPort, function() {
console.log('Listening... [press Control-C to exit]');
}).on('error', function (err, req, res) {
console.log(err.stack);
Expand Down