devtunnel-cli 3.0.18 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/start.js +25 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devtunnel-cli",
3
- "version": "3.0.18",
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
@@ -69,6 +69,22 @@ function checkPortInUse(port) {
69
69
  });
70
70
  }
71
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
+
72
88
  // Detect port from package.json
73
89
  function detectPortFromPackage(packagePath) {
74
90
  try {
@@ -536,7 +552,7 @@ async function main() {
536
552
  console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
537
553
  console.log("");
538
554
 
539
- // 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
540
556
  let staticServerProcess = null;
541
557
  const isHtmlProject = !!detectHtmlProject(projectPath);
542
558
  const portInUseNow = await checkPortInUse(devPort);
@@ -548,8 +564,14 @@ async function main() {
548
564
  shell: false
549
565
  });
550
566
  staticServerProcess.on("error", () => {});
551
- await new Promise((r) => setTimeout(r, 1200));
552
- console.log(`Static server running at http://localhost:${devPort}`);
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);
553
575
  console.log("");
554
576
  }
555
577