-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevents.mjs
45 lines (34 loc) · 1 KB
/
events.mjs
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Tunnel, ConfigHandler } from "cloudflared";
const token = process.env.CLOUDFLARED_TOKEN;
if (!token) {
throw new Error("CLOUDFLARED_TOKEN is not set");
}
const tunnel = Tunnel.withToken(token);
const handler = new ConfigHandler(tunnel);
handler.on("config", ({ config }) => {
console.log("Config", config);
});
tunnel.on("url", (url) => {
console.log("Tunnel is ready at", url);
});
tunnel.on("connected", (connection) => {
console.log("Connected to", connection);
});
tunnel.on("disconnected", (connection) => {
console.log("Disconnected from", connection);
});
tunnel.on("stdout", (data) => {
console.log("Tunnel stdout", data);
});
tunnel.on("stderr", (data) => {
console.error("Tunnel stderr", data);
});
tunnel.on("exit", (code, signal) => {
console.log("Tunnel exited with code", code, "and signal", signal);
});
tunnel.on("error", (error) => {
console.error("Error", error);
});
process.on("SIGINT", () => {
console.log("Tunnel stopped", tunnel.stop());
});