-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
54 lines (41 loc) · 1.08 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var https = require('https');
var tunnel = require('./lib/tunnel');
var WebSocket = require('hyco-websocket');
var argv = require('optimist').argv;
var ns = process.env.RELAYNAMESPACE;
var path = process.env.RELAYPATH;
var keyrule = process.env.RELAYRULENAME;
var key = process.env.RELAYKEY;
var host = process.env.PORT;
var credentials, tunnels = [];
if ((!ns && !path && !keyrule && !host)) {
if (argv._.length < 4) {
console.log('connect.js [namespace] [path] [key-rule] [key] [port]')
process.exit(1);
}
else {
ns = argv._[0];
path = argv._[1];
keyrule = argv._[2];
key = argv._[3];
host = argv._[4];
}
}
var server = WebSocket.createRelaySendUri(ns, path);
var token = WebSocket.createRelayToken('https://' + ns, keyrule, key);
tunnel.createTunnel(server, token, host, function (err, server) {
if (err) {
log(String(err));
} else {
var id = tunnels.push(server);
log('Tunnel created with id: ' + id);
}
});
log('Remote Host: ' + ns);
function log(s) {
if (global.shell) {
global.shell.echo(s);
} else {
console.log(s);
}
}