-
Notifications
You must be signed in to change notification settings - Fork 1
use wstunnel lib to create your own tunnel
arily edited this page Jan 26, 2020
·
8 revisions
const wsTunnelServer = require('./requires/wsServer');
run in a http server
const http = require('http');
const url = require('url');
const s = new wsTunnelServer({
noServer: true,
clientTracking: 0,
},
wspath || '/');
server.on('upgrade',function(request, socket, head) {
const pathname = url.parse(request.url).pathname;
pattern = 'http://dummy'.concat(wspath, '/*');
if (match(pattern, 'http://dummy' + pathname)) {
s.server.handleUpgrade(request, socket, head, function done(ws) {
//do your stuff here
s.server.emit('connection', ws, request);
});
} else {
socket.destroy();
}
});
without http server
const s = new wsTunnelServer({
port:port,
clientTracking: 0,
},