devtunnel-cli 3.0.44 → 3.1.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.
- package/README.md +152 -141
- package/package.json +89 -85
- package/src/core/RUN.js +64 -64
- package/src/core/index.js +374 -374
- package/src/core/proxy-server.js +105 -105
- package/src/core/setup-cloudflared.js +427 -427
- package/src/core/start.js +2 -2
- package/src/core/static-server.js +109 -109
- package/src/utils/folder-picker.js +140 -140
- package/src/utils/pages/index.html +1 -1
- package/src/utils/postinstall-global-check.cjs +15 -0
- package/src/utils/tunnel-helpers.js +35 -35
package/src/core/proxy-server.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
import http from "http";
|
|
2
|
-
|
|
3
|
-
// Suppress util._extend deprecation from http-proxy (must run before loading http-proxy)
|
|
4
|
-
const _origEmit = process.emitWarning;
|
|
5
|
-
process.emitWarning = function (warning, ...args) {
|
|
6
|
-
if (typeof warning === "string" && warning.includes("util._extend")) return;
|
|
7
|
-
return _origEmit.apply(this, [warning, ...args]);
|
|
8
|
-
};
|
|
9
|
-
const { default: httpProxy } = await import("http-proxy");
|
|
10
|
-
|
|
11
|
-
// Get ports and optional base path from command line
|
|
12
|
-
const TARGET_PORT = parseInt(process.argv[2]); // Your dev server port
|
|
13
|
-
const PROXY_PORT = parseInt(process.argv[3]); // Port for tunnel to connect to
|
|
14
|
-
const PROJECT_NAME = process.argv[4] || "Project";
|
|
15
|
-
const BASE_PATH = process.argv[5] || ""; // e.g. /PeopleQ for XAMPP htdocs/PeopleQ
|
|
16
|
-
|
|
17
|
-
if (!TARGET_PORT || !PROXY_PORT) {
|
|
18
|
-
console.error("Usage: node proxy-server.js <target-port> <proxy-port> [project-name] [base-path]");
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Create proxy with streaming support
|
|
23
|
-
const proxy = httpProxy.createProxyServer({
|
|
24
|
-
target: `http://localhost:${TARGET_PORT}`,
|
|
25
|
-
changeOrigin: true,
|
|
26
|
-
ws: true, // Enable WebSocket proxying (for HMR)
|
|
27
|
-
xfwd: true,
|
|
28
|
-
timeout: 300000, // 5 minutes timeout for large files
|
|
29
|
-
proxyTimeout: 300000, // 5 minutes proxy timeout
|
|
30
|
-
followRedirects: true
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Handle proxy errors
|
|
34
|
-
proxy.on("error", (err, req, res) => {
|
|
35
|
-
console.error("Proxy error:", err.message);
|
|
36
|
-
if (res.writeHead) {
|
|
37
|
-
res.writeHead(502, { "Content-Type": "text/plain" });
|
|
38
|
-
res.end("Bad Gateway: Could not connect to your dev server.\nMake sure it's running on port " + TARGET_PORT);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Create HTTP server with timeout handling
|
|
43
|
-
const server = http.createServer((req, res) => {
|
|
44
|
-
// Set longer timeout for large file transfers
|
|
45
|
-
req.setTimeout(300000); // 5 minutes
|
|
46
|
-
res.setTimeout(300000); // 5 minutes
|
|
47
|
-
|
|
48
|
-
// Add CORS headers
|
|
49
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
50
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
51
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
52
|
-
|
|
53
|
-
// Handle timeout
|
|
54
|
-
req.on('timeout', () => {
|
|
55
|
-
if (!res.headersSent) {
|
|
56
|
-
res.writeHead(408, { "Content-Type": "text/plain" });
|
|
57
|
-
res.end("Request timeout");
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (req.method === "OPTIONS") {
|
|
62
|
-
res.writeHead(200);
|
|
63
|
-
res.end();
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// XAMPP subfolder: rewrite path so / → /PeopleQ/, /style.css → /PeopleQ/style.css
|
|
68
|
-
if (BASE_PATH) {
|
|
69
|
-
const prefix = BASE_PATH.replace(/\/$/, "");
|
|
70
|
-
req.url = prefix + (req.url === "/" ? "/" : req.url);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Proxy the request
|
|
74
|
-
proxy.web(req, res);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Handle WebSocket upgrade (for Vite HMR)
|
|
78
|
-
server.on("upgrade", (req, socket, head) => {
|
|
79
|
-
if (BASE_PATH) {
|
|
80
|
-
const prefix = BASE_PATH.replace(/\/$/, "");
|
|
81
|
-
req.url = prefix + (req.url === "/" ? "/" : req.url);
|
|
82
|
-
}
|
|
83
|
-
proxy.ws(req, socket, head);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Start server
|
|
87
|
-
server.listen(PROXY_PORT, () => {
|
|
88
|
-
console.log("");
|
|
89
|
-
console.log("DevTunnel Proxy Server");
|
|
90
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
91
|
-
console.log(`Project: ${PROJECT_NAME}`);
|
|
92
|
-
console.log(`Dev Server: http://localhost:${TARGET_PORT}${BASE_PATH || ""}`);
|
|
93
|
-
console.log(`Proxy Port: ${PROXY_PORT}`);
|
|
94
|
-
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
95
|
-
console.log("Ready! Tunnel will connect to proxy");
|
|
96
|
-
console.log("No config changes needed");
|
|
97
|
-
console.log("");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Handle shutdown
|
|
101
|
-
process.on("SIGINT", () => {
|
|
102
|
-
console.log("\nShutting down proxy...");
|
|
103
|
-
server.close();
|
|
104
|
-
process.exit(0);
|
|
105
|
-
});
|
|
1
|
+
import http from "http";
|
|
2
|
+
|
|
3
|
+
// Suppress util._extend deprecation from http-proxy (must run before loading http-proxy)
|
|
4
|
+
const _origEmit = process.emitWarning;
|
|
5
|
+
process.emitWarning = function (warning, ...args) {
|
|
6
|
+
if (typeof warning === "string" && warning.includes("util._extend")) return;
|
|
7
|
+
return _origEmit.apply(this, [warning, ...args]);
|
|
8
|
+
};
|
|
9
|
+
const { default: httpProxy } = await import("http-proxy");
|
|
10
|
+
|
|
11
|
+
// Get ports and optional base path from command line
|
|
12
|
+
const TARGET_PORT = parseInt(process.argv[2]); // Your dev server port
|
|
13
|
+
const PROXY_PORT = parseInt(process.argv[3]); // Port for tunnel to connect to
|
|
14
|
+
const PROJECT_NAME = process.argv[4] || "Project";
|
|
15
|
+
const BASE_PATH = process.argv[5] || ""; // e.g. /PeopleQ for XAMPP htdocs/PeopleQ
|
|
16
|
+
|
|
17
|
+
if (!TARGET_PORT || !PROXY_PORT) {
|
|
18
|
+
console.error("Usage: node proxy-server.js <target-port> <proxy-port> [project-name] [base-path]");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Create proxy with streaming support
|
|
23
|
+
const proxy = httpProxy.createProxyServer({
|
|
24
|
+
target: `http://localhost:${TARGET_PORT}`,
|
|
25
|
+
changeOrigin: true,
|
|
26
|
+
ws: true, // Enable WebSocket proxying (for HMR)
|
|
27
|
+
xfwd: true,
|
|
28
|
+
timeout: 300000, // 5 minutes timeout for large files
|
|
29
|
+
proxyTimeout: 300000, // 5 minutes proxy timeout
|
|
30
|
+
followRedirects: true
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Handle proxy errors
|
|
34
|
+
proxy.on("error", (err, req, res) => {
|
|
35
|
+
console.error("Proxy error:", err.message);
|
|
36
|
+
if (res.writeHead) {
|
|
37
|
+
res.writeHead(502, { "Content-Type": "text/plain" });
|
|
38
|
+
res.end("Bad Gateway: Could not connect to your dev server.\nMake sure it's running on port " + TARGET_PORT);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Create HTTP server with timeout handling
|
|
43
|
+
const server = http.createServer((req, res) => {
|
|
44
|
+
// Set longer timeout for large file transfers
|
|
45
|
+
req.setTimeout(300000); // 5 minutes
|
|
46
|
+
res.setTimeout(300000); // 5 minutes
|
|
47
|
+
|
|
48
|
+
// Add CORS headers
|
|
49
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
50
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
51
|
+
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
52
|
+
|
|
53
|
+
// Handle timeout
|
|
54
|
+
req.on('timeout', () => {
|
|
55
|
+
if (!res.headersSent) {
|
|
56
|
+
res.writeHead(408, { "Content-Type": "text/plain" });
|
|
57
|
+
res.end("Request timeout");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (req.method === "OPTIONS") {
|
|
62
|
+
res.writeHead(200);
|
|
63
|
+
res.end();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// XAMPP subfolder: rewrite path so / → /PeopleQ/, /style.css → /PeopleQ/style.css
|
|
68
|
+
if (BASE_PATH) {
|
|
69
|
+
const prefix = BASE_PATH.replace(/\/$/, "");
|
|
70
|
+
req.url = prefix + (req.url === "/" ? "/" : req.url);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Proxy the request
|
|
74
|
+
proxy.web(req, res);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Handle WebSocket upgrade (for Vite HMR)
|
|
78
|
+
server.on("upgrade", (req, socket, head) => {
|
|
79
|
+
if (BASE_PATH) {
|
|
80
|
+
const prefix = BASE_PATH.replace(/\/$/, "");
|
|
81
|
+
req.url = prefix + (req.url === "/" ? "/" : req.url);
|
|
82
|
+
}
|
|
83
|
+
proxy.ws(req, socket, head);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Start server
|
|
87
|
+
server.listen(PROXY_PORT, () => {
|
|
88
|
+
console.log("");
|
|
89
|
+
console.log("DevTunnel Proxy Server");
|
|
90
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
91
|
+
console.log(`Project: ${PROJECT_NAME}`);
|
|
92
|
+
console.log(`Dev Server: http://localhost:${TARGET_PORT}${BASE_PATH || ""}`);
|
|
93
|
+
console.log(`Proxy Port: ${PROXY_PORT}`);
|
|
94
|
+
console.log("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
|
|
95
|
+
console.log("Ready! Tunnel will connect to proxy");
|
|
96
|
+
console.log("No config changes needed");
|
|
97
|
+
console.log("");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Handle shutdown
|
|
101
|
+
process.on("SIGINT", () => {
|
|
102
|
+
console.log("\nShutting down proxy...");
|
|
103
|
+
server.close();
|
|
104
|
+
process.exit(0);
|
|
105
|
+
});
|