Do not set rejectUnauthorized by default in wsProxy.

This commit is contained in:
Julien Fontanet 2015-05-19 12:27:02 +02:00
parent 523a30afb4
commit 65daa23a74
2 changed files with 19 additions and 22 deletions

View File

@ -324,7 +324,9 @@ const setUpConsoleProxy = (webServer, xo) => {
// FIXME: lost connection due to VM restart is not detected.
webSocketServer.handleUpgrade(req, socket, head, connection => {
wsProxy(connection, url)
wsProxy(connection, url, {
rejectUnauthorized: false
})
})
})
}

View File

@ -6,46 +6,41 @@ const debug = createDebug('xo:wsProxy')
const defaults = {
// Automatically close the client connection when the remote close.
autoClose: true,
// Reject secure connections to unauthorized remotes (bad CA).
rejectUnauthorized: false
autoClose: true
}
// Proxy a WebSocket `client` to a remote server which has `url` as
// address.
export default function wsProxy (client, url, opts) {
opts = assign({}, defaults, opts)
const autoClose = !!opts.autoClose
delete opts.autoClose
const remote = new WebSocket(url, {
protocol: opts.protocol || client.protocol,
rejectUnauthorized: opts.rejectUnauthorized
}).once('open', function () {
debug('connected to', url)
function onClientSendError (error) {
debug('client send error', error)
}
function onRemoteSendError (error) {
debug('remote send error', error)
}
const remote = new WebSocket(url, opts).once('open', function () {
debug('connected to %s', url)
}).once('close', function () {
debug('remote closed')
if (opts.autoClose) {
if (autoClose) {
client.close()
}
}).once('error', function (error) {
debug('remote error', error)
debug('remote error: %s', error)
}).on('message', function (message) {
client.send(message, function (error) {
if (error) {
debug('client send error', error)
}
})
client.send(message, onClientSendError)
})
client.once('close', function () {
debug('client closed')
remote.close()
}).on('message', function (message) {
remote.send(message, function (error) {
if (error) {
debug('remote send error', error)
}
})
remote.send(message, onRemoteSendError)
})
}