devtunnel-cli 3.0.22 → 3.0.23
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 +2 -2
- package/src/core/static-server.js +25 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "devtunnel-cli",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.23",
|
|
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
|
@@ -17,10 +17,10 @@ function getPackageVersion() {
|
|
|
17
17
|
const pkgPath = join(PROJECT_ROOT, "package.json");
|
|
18
18
|
if (existsSync(pkgPath)) {
|
|
19
19
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
20
|
-
return pkg.version || "3.0.
|
|
20
|
+
return pkg.version || "3.0.23";
|
|
21
21
|
}
|
|
22
22
|
} catch (err) {}
|
|
23
|
-
return "3.0.
|
|
23
|
+
return "3.0.23";
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Helper to run command
|
|
@@ -34,7 +34,10 @@ const server = http.createServer((req, res) => {
|
|
|
34
34
|
res.end("Method Not Allowed");
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
// Use only pathname (strip query string and hash) so /style.css?v=1 resolves to style.css
|
|
38
|
+
const pathname = (req.url || "/").split("?")[0].split("#")[0];
|
|
39
|
+
const relative = path.normalize(pathname).replace(/^\//, "") || ".";
|
|
40
|
+
let p = path.join(ROOT, relative);
|
|
38
41
|
if (!path.isAbsolute(p)) p = path.join(ROOT, p);
|
|
39
42
|
if (!p.startsWith(ROOT)) {
|
|
40
43
|
res.writeHead(403, { "Content-Type": "text/plain" });
|
|
@@ -66,15 +69,33 @@ function serveFile(filePath, stat, req, res) {
|
|
|
66
69
|
const ext = path.extname(filePath);
|
|
67
70
|
const contentType = MIME[ext] || "application/octet-stream";
|
|
68
71
|
res.setHeader("Content-Type", contentType);
|
|
69
|
-
res.setHeader("Content-Length", stat.size);
|
|
70
72
|
if (req.method === "HEAD") {
|
|
73
|
+
res.setHeader("Content-Length", stat.size);
|
|
71
74
|
res.end();
|
|
72
75
|
return;
|
|
73
76
|
}
|
|
77
|
+
// For HTML: rewrite absolute localhost URLs so CSS/JS work when viewed through tunnel
|
|
78
|
+
if (ext === ".html" || ext === ".htm") {
|
|
79
|
+
try {
|
|
80
|
+
let body = fs.readFileSync(filePath, "utf8");
|
|
81
|
+
body = body.replace(/https?:\/\/127\.0\.0\.1:\d+\//g, "/");
|
|
82
|
+
body = body.replace(/https?:\/\/localhost:\d+\//g, "/");
|
|
83
|
+
res.setHeader("Content-Length", Buffer.byteLength(body, "utf8"));
|
|
84
|
+
res.end(body);
|
|
85
|
+
return;
|
|
86
|
+
} catch (err) {
|
|
87
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
88
|
+
res.end("Internal Server Error");
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
res.setHeader("Content-Length", stat.size);
|
|
74
93
|
const stream = fs.createReadStream(filePath);
|
|
75
94
|
stream.on("error", () => {
|
|
76
|
-
res.
|
|
77
|
-
|
|
95
|
+
if (!res.headersSent) {
|
|
96
|
+
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
97
|
+
res.end("Internal Server Error");
|
|
98
|
+
}
|
|
78
99
|
});
|
|
79
100
|
stream.pipe(res);
|
|
80
101
|
}
|