devtunnel-cli 3.0.17 → 3.0.19
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/package.json +1 -1
- package/src/core/start.js +37 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devtunnel-cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DevTunnel - Share local dev servers worldwide. Zero configuration tunnel for any framework. Install via npm: npm install -g devtunnel-cli. Works with Vite, React, Next.js, Express, NestJS, Laravel (PHP), HTML, and more.",
|
|
6
6
|
"main": "src/core/start.js",
|
package/src/core/start.js
CHANGED
|
@@ -12,6 +12,17 @@ const __dirname = dirname(__filename);
|
|
|
12
12
|
// Get project root directory dynamically (two levels up from src/core/)
|
|
13
13
|
const PROJECT_ROOT = dirname(dirname(__dirname));
|
|
14
14
|
|
|
15
|
+
function getPackageVersion() {
|
|
16
|
+
try {
|
|
17
|
+
const pkgPath = join(PROJECT_ROOT, "package.json");
|
|
18
|
+
if (existsSync(pkgPath)) {
|
|
19
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
20
|
+
return pkg.version || "3.0.17";
|
|
21
|
+
}
|
|
22
|
+
} catch (err) {}
|
|
23
|
+
return "3.0.17";
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
// Helper to run command
|
|
16
27
|
function runCommand(command, args = [], cwd = process.cwd()) {
|
|
17
28
|
return new Promise((resolve) => {
|
|
@@ -58,6 +69,22 @@ function checkPortInUse(port) {
|
|
|
58
69
|
});
|
|
59
70
|
}
|
|
60
71
|
|
|
72
|
+
// Poll until server at port responds (for HTML built-in static server)
|
|
73
|
+
async function waitForServerReady(port, timeoutMs = 10000) {
|
|
74
|
+
const start = Date.now();
|
|
75
|
+
while (Date.now() - start < timeoutMs) {
|
|
76
|
+
try {
|
|
77
|
+
const code = await new Promise((resolve) => {
|
|
78
|
+
const req = http.get(`http://127.0.0.1:${port}`, { timeout: 2000 }, (res) => resolve(res.statusCode));
|
|
79
|
+
req.on("error", () => resolve(null));
|
|
80
|
+
});
|
|
81
|
+
if (code !== null && code >= 200 && code < 500) return true;
|
|
82
|
+
} catch (err) {}
|
|
83
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
|
|
61
88
|
// Detect port from package.json
|
|
62
89
|
function detectPortFromPackage(packagePath) {
|
|
63
90
|
try {
|
|
@@ -219,7 +246,7 @@ async function main() {
|
|
|
219
246
|
// Show ASCII logo
|
|
220
247
|
showLogo();
|
|
221
248
|
|
|
222
|
-
console.log(
|
|
249
|
+
console.log(`DevTunnel v${getPackageVersion()}`);
|
|
223
250
|
console.log("Share your local dev servers worldwide");
|
|
224
251
|
console.log("");
|
|
225
252
|
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
@@ -525,7 +552,7 @@ async function main() {
|
|
|
525
552
|
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
526
553
|
console.log("");
|
|
527
554
|
|
|
528
|
-
// For HTML projects with no server running: start built-in static server
|
|
555
|
+
// For HTML projects with no server running: start built-in static server and confirm it works
|
|
529
556
|
let staticServerProcess = null;
|
|
530
557
|
const isHtmlProject = !!detectHtmlProject(projectPath);
|
|
531
558
|
const portInUseNow = await checkPortInUse(devPort);
|
|
@@ -537,8 +564,14 @@ async function main() {
|
|
|
537
564
|
shell: false
|
|
538
565
|
});
|
|
539
566
|
staticServerProcess.on("error", () => {});
|
|
540
|
-
|
|
541
|
-
|
|
567
|
+
const ready = await waitForServerReady(devPort, 10000);
|
|
568
|
+
if (!ready) {
|
|
569
|
+
if (staticServerProcess) staticServerProcess.kill();
|
|
570
|
+
console.log("");
|
|
571
|
+
console.log("ERROR: Built-in static server did not start in time. Check that port " + devPort + " is free.");
|
|
572
|
+
process.exit(1);
|
|
573
|
+
}
|
|
574
|
+
console.log("Static server ready at http://localhost:" + devPort);
|
|
542
575
|
console.log("");
|
|
543
576
|
}
|
|
544
577
|
|