-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtunnel.js
More file actions
29 lines (22 loc) · 781 Bytes
/
tunnel.js
File metadata and controls
29 lines (22 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require("node:fs");
const { Tunnel, bin, install } = require("cloudflared");
console.log("Cloudflared Tunnel Example.");
main();
async function main() {
if (!fs.existsSync(bin)) {
// install cloudflared binary
await install(bin);
}
// run: cloudflared tunnel --hello-world
const tunnel = Tunnel.quick();
// show the url
const url = new Promise((resolve) => tunnel.once("url", resolve));
console.log("LINK:", await url);
const conn = new Promise((resolve) => tunnel.once("connected", resolve));
console.log("CONN:", await conn);
// stop the tunnel after 15 seconds
setTimeout(tunnel.stop, 15_000);
tunnel.on("exit", (code) => {
console.log("tunnel process exited with code", code);
});
}