stackedge 1.1.0 → 1.1.2
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.
- package/bin/stackedge.js +13 -25
- package/package.json +1 -1
package/bin/stackedge.js
CHANGED
|
@@ -12,7 +12,6 @@ const { spawn } = require("child_process");
|
|
|
12
12
|
const net = require("net");
|
|
13
13
|
const fs = require("fs-extra");
|
|
14
14
|
const path = require("path");
|
|
15
|
-
const crypto = require("crypto");
|
|
16
15
|
|
|
17
16
|
/* =========================
|
|
18
17
|
TOR CONSTANTS
|
|
@@ -51,10 +50,7 @@ async function waitForPort(port, timeout = 15000) {
|
|
|
51
50
|
try {
|
|
52
51
|
await new Promise((res, rej) => {
|
|
53
52
|
const s = net.createConnection(port, "127.0.0.1");
|
|
54
|
-
s.once("connect", () => {
|
|
55
|
-
s.end();
|
|
56
|
-
res();
|
|
57
|
-
});
|
|
53
|
+
s.once("connect", () => { s.end(); res(); });
|
|
58
54
|
s.once("error", rej);
|
|
59
55
|
});
|
|
60
56
|
return;
|
|
@@ -89,10 +85,7 @@ Log notice stdout
|
|
|
89
85
|
async function isTorRunning() {
|
|
90
86
|
return new Promise((resolve) => {
|
|
91
87
|
const socket = net.createConnection(CONTROL_PORT, "127.0.0.1");
|
|
92
|
-
socket.once("connect", () => {
|
|
93
|
-
socket.end();
|
|
94
|
-
resolve(true);
|
|
95
|
-
});
|
|
88
|
+
socket.once("connect", () => { socket.end(); resolve(true); });
|
|
96
89
|
socket.once("error", () => resolve(false));
|
|
97
90
|
});
|
|
98
91
|
}
|
|
@@ -149,7 +142,7 @@ async function waitForTorBootstrap() {
|
|
|
149
142
|
}
|
|
150
143
|
|
|
151
144
|
/* =========================
|
|
152
|
-
HIDDEN SERVICE
|
|
145
|
+
HIDDEN SERVICE MANAGEMENT
|
|
153
146
|
========================= */
|
|
154
147
|
|
|
155
148
|
async function addHiddenService(name, ports) {
|
|
@@ -159,13 +152,10 @@ async function addHiddenService(name, ports) {
|
|
|
159
152
|
|
|
160
153
|
const lines = [
|
|
161
154
|
`HiddenServiceDir ${hsPath}`,
|
|
162
|
-
...ports.map(p =>
|
|
163
|
-
`HiddenServicePort ${p.virtual} 127.0.0.1:${p.target}`
|
|
164
|
-
)
|
|
155
|
+
...ports.map(p => `HiddenServicePort ${p.virtual} 127.0.0.1:${p.target}`)
|
|
165
156
|
];
|
|
166
157
|
|
|
167
158
|
await fs.appendFile(TORRC, "\n" + lines.join("\n") + "\n");
|
|
168
|
-
|
|
169
159
|
await torControl("SIGNAL RELOAD");
|
|
170
160
|
|
|
171
161
|
const hostnamePath = path.join(hsPath, "hostname");
|
|
@@ -181,7 +171,6 @@ async function addHiddenService(name, ports) {
|
|
|
181
171
|
|
|
182
172
|
async function cleanupOrphans(apps) {
|
|
183
173
|
const active = new Set(apps.map(a => a.name));
|
|
184
|
-
|
|
185
174
|
if (!await fs.pathExists(TOR_HS_DIR)) return;
|
|
186
175
|
|
|
187
176
|
for (const dir of await fs.readdir(TOR_HS_DIR)) {
|
|
@@ -208,10 +197,12 @@ program.command("start <name>")
|
|
|
208
197
|
const command = process.argv.slice(idx + 1).join(" ");
|
|
209
198
|
const apps = await loadApps();
|
|
210
199
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
200
|
+
// Use custom ports if provided via env, otherwise allocate dynamically
|
|
201
|
+
const httpPort = Number(process.env.PORT || await getFreePort());
|
|
202
|
+
const sslPort = process.env.SSL_PORT ? Number(process.env.SSL_PORT) : null;
|
|
203
|
+
|
|
204
|
+
const ports = [{ virtual: 80, target: httpPort }];
|
|
205
|
+
if (sslPort) ports.push({ virtual: 443, target: sslPort });
|
|
215
206
|
|
|
216
207
|
await startTorOnce();
|
|
217
208
|
await waitForTorBootstrap();
|
|
@@ -222,13 +213,10 @@ program.command("start <name>")
|
|
|
222
213
|
cwd: process.cwd(),
|
|
223
214
|
detached: true,
|
|
224
215
|
stdio: "ignore",
|
|
225
|
-
env: {
|
|
226
|
-
...process.env,
|
|
227
|
-
PORT: String(ports[0].target),
|
|
228
|
-
SSL_PORT: String(ports[1].target)
|
|
229
|
-
}
|
|
216
|
+
env: { ...process.env, PORT: String(httpPort), SSL_PORT: sslPort ? String(sslPort) : undefined }
|
|
230
217
|
});
|
|
231
218
|
|
|
219
|
+
// Wait for all mapped ports
|
|
232
220
|
for (const p of ports) await waitForPort(p.target);
|
|
233
221
|
|
|
234
222
|
const onion = await addHiddenService(name, ports);
|
|
@@ -247,7 +235,7 @@ program.command("start <name>")
|
|
|
247
235
|
await saveApps(apps);
|
|
248
236
|
|
|
249
237
|
console.log(`✔ ${name} running in background`);
|
|
250
|
-
console.log(`🌐
|
|
238
|
+
console.log(`🌐 http${sslPort ? "s" : ""}://${onion}`);
|
|
251
239
|
});
|
|
252
240
|
|
|
253
241
|
/* =========================
|