-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
60 lines (41 loc) · 1.67 KB
/
main.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
55
56
57
58
59
60
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var _telehash = require("telehash");
var _telehash2 = _interopRequireDefault(_telehash);
var _http = require("http");
var _http2 = _interopRequireDefault(_http);
var _serverServerJs = require("./server/server.js");
var _serverServerJs2 = _interopRequireDefault(_serverServerJs);
var teletunnel = function teletunnel(proxy, _ref, cb) {
var hostname = _ref.hostname;
var port = _ref.port;
var subdomain = _ref.subdomain;
var mesh = _ref.mesh;
proxy = typeof proxy === "number" ? "http://127.0.0.1:" + proxy : typeof proxy === "object" ? proxy : null;
if (!proxy) throw new Error("invalid local argument");
function onMesh(err, mesh) {
console.log("onmesh");
if (err) throw err;
function onRemote(res) {
res.on("data", function (data) {
var server = mesh.link(JSON.parse(data.toString()));
server.status(function (err, status) {
console.log("server link up: ", status.up);
var url = "http://" + mesh.hashname.substr(0, 8) + "." + hostname + ":" + port;
mesh.proxy(proxy);
cb(null, url);
});
});
}
var url = "http://" + hostname + ":" + port + "/telehash.hashname";
console.log("url", url);
_http2["default"].request(url, onRemote).on("error", cb).end();
}
if (!mesh) _telehash2["default"].load({ id: process.cwd() + "/.teletunnel_local_id" }, onMesh);else onMesh(null, onMesh);
};
teletunnel.Server = _serverServerJs2["default"];
exports["default"] = teletunnel;
module.exports = exports["default"];