relayy-tunnel 1.0.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/index.js +81 -0
- package/package.json +26 -0
package/index.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const port = process.argv[2];
|
|
4
|
+
|
|
5
|
+
if(!port) {
|
|
6
|
+
console.log("Usage: cli <port>");
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const WebSocket = require("ws");
|
|
11
|
+
const ora = require("ora").default;
|
|
12
|
+
const chalk = require("chalk").default;
|
|
13
|
+
const axios = require("axios");
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const ws = new WebSocket("wss://relayy.up.railway.app/");
|
|
17
|
+
|
|
18
|
+
const spinner = ora("Connecting to server...").start();
|
|
19
|
+
|
|
20
|
+
ws.on("open", () => {
|
|
21
|
+
|
|
22
|
+
spinner.succeed("Connected to tunnel server");
|
|
23
|
+
|
|
24
|
+
ws.send(
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
type: "register",
|
|
27
|
+
port: port
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
ws.on("message", async (message) => {
|
|
33
|
+
|
|
34
|
+
const data = JSON.parse(message);
|
|
35
|
+
|
|
36
|
+
if(data.type === "tunnel_created") {
|
|
37
|
+
|
|
38
|
+
const url = `https://relayy.up.railway.app/${data.tunnelId}`;
|
|
39
|
+
|
|
40
|
+
console.log("\n" + chalk.green("Tunnel is live!"));
|
|
41
|
+
|
|
42
|
+
console.log("\nPublic URL:");
|
|
43
|
+
console.log(chalk.cyan(url));
|
|
44
|
+
const expiryTime = new Date(data.expiry);
|
|
45
|
+
console.log(chalk.yellow(`\nNote: This tunnel will expire at ${expiryTime.toLocaleTimeString()}.`));
|
|
46
|
+
}
|
|
47
|
+
else if(data.type === "request") {
|
|
48
|
+
try{
|
|
49
|
+
const response = await axios({
|
|
50
|
+
method: data.method,
|
|
51
|
+
url: `http://localhost:${port}${data.path}`,
|
|
52
|
+
data: data.body
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
ws.send(
|
|
56
|
+
JSON.stringify({
|
|
57
|
+
type: "response",
|
|
58
|
+
requestId: data.requestId,
|
|
59
|
+
status: response.status,
|
|
60
|
+
body: response.data
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
catch(error){
|
|
65
|
+
|
|
66
|
+
ws.send(
|
|
67
|
+
JSON.stringify({
|
|
68
|
+
type: "response",
|
|
69
|
+
requestId: data.requestId,
|
|
70
|
+
status: 500,
|
|
71
|
+
body: "Local server error"
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if(data.type === "tunnel_expired") {
|
|
77
|
+
console.log(chalk.red("\nTunnel has expired. Please restart the CLI."));
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "relayy-tunnel",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"bin": {
|
|
9
|
+
"relayy": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"cli",
|
|
13
|
+
"tunnel",
|
|
14
|
+
"public-url",
|
|
15
|
+
"local-server"
|
|
16
|
+
],
|
|
17
|
+
"author": "Kedar Sawant",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"description": "A simple CLI for creating public URLs for local servers",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"axios": "^1.13.6",
|
|
22
|
+
"chalk": "^5.6.2",
|
|
23
|
+
"ora": "^9.3.0",
|
|
24
|
+
"ws": "^8.19.0"
|
|
25
|
+
}
|
|
26
|
+
}
|