locadot 2.0.0 → 2.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,18 @@ const api_1 = require("./api");
10
10
  const system_1 = require("../lib/system");
11
11
  const tunnel_1 = require("../proxy/tunnel");
12
12
  const urls_1 = require("../lib/urls");
13
+ const localhost_1 = __importDefault(require("../lib/localhost"));
14
+ const remote_1 = require("../proxy/remote");
15
+ const remotes_1 = __importDefault(require("../lib/remotes"));
16
+ /** A remote mapping is only reachable through its sender, with the peer's credentials. */
17
+ function probeEntry(ctx, entry) {
18
+ if (!entry.remote)
19
+ return ctx.probe(entry.target);
20
+ const remote = (0, remote_1.remoteFor)(entry.remote.name);
21
+ if (!remote)
22
+ return Promise.resolve({ up: false, error: "disconnected" });
23
+ return localhost_1.default.probe(remote.url, 3000, false, { "X-Locadot-Peer": remote.token, "X-Locadot-Host": entry.remote.host });
24
+ }
13
25
  function hostUrls(host, httpPort, httpsPort) {
14
26
  return { https: (0, urls_1.formatUrl)(host, true, httpsPort), http: (0, urls_1.formatUrl)(host, false, httpPort) };
15
27
  }
@@ -37,7 +49,7 @@ async function buildHosts(ctx) {
37
49
  const { httpPort, httpsPort } = ctx.proxyInfo;
38
50
  const entries = Object.entries(registry.hosts);
39
51
  const rows = await Promise.all(entries.map(async ([host, entry]) => {
40
- const probe = await ctx.probe(entry.target);
52
+ const probe = await probeEntry(ctx, entry);
41
53
  return {
42
54
  host,
43
55
  target: entry.target,
@@ -49,6 +61,9 @@ async function buildHosts(ctx) {
49
61
  stats: stats[host] ?? null,
50
62
  probe,
51
63
  tunnel: ctx.tunnel(host),
64
+ remote: entry.remote
65
+ ? { name: entry.remote.name, host: entry.remote.host, role: remotes_1.default.get(entry.remote.name)?.role ?? "viewer" }
66
+ : undefined,
52
67
  };
53
68
  }));
54
69
  return rows.sort((a, b) => a.host.localeCompare(b.host));
@@ -97,7 +112,13 @@ function handleDashboardRequest(req, res, ctx) {
97
112
  case "/api/status": {
98
113
  const uptimeSec = Math.max(0, Math.round((Date.now() - new Date(ctx.proxyInfo.startedAt).getTime()) / 1000));
99
114
  (0, system_1.systemStatus)(ctx.proxyInfo.caTrusted)
100
- .then((system) => sendJson(res, method, 200, { proxy: ctx.proxyInfo, uptimeSec, hosts: Object.keys(ctx.getRegistry().hosts).length, system: { ...system, cloudflared: (0, tunnel_1.cloudflaredInfo)() } }))
115
+ .then((system) => sendJson(res, method, 200, {
116
+ proxy: ctx.proxyInfo,
117
+ uptimeSec,
118
+ hosts: Object.keys(ctx.getRegistry().hosts).length,
119
+ system: { ...system, cloudflared: (0, tunnel_1.cloudflaredInfo)() },
120
+ hub: ctx.hub(),
121
+ }))
101
122
  .catch(fail);
102
123
  return;
103
124
  }