@rubriclab/bunl 0.1.25 → 0.2.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/.env.example +2 -1
- package/.github/workflows/publish.yml +16 -0
- package/.vscode/settings.json +16 -0
- package/Dockerfile +6 -8
- package/LICENSE +1 -1
- package/biome.json +3 -0
- package/build/client.js +93 -470
- package/bun.lock +153 -0
- package/client.ts +129 -85
- package/demo.ts +79 -12
- package/docker-compose.yml +36 -0
- package/e2e.test.ts +189 -0
- package/package.json +47 -44
- package/server.ts +146 -83
- package/tsconfig.json +3 -3
- package/types.ts +26 -9
- package/utils.ts +119 -6
- package/bun.lockb +0 -0
- package/fly.toml +0 -19
- package/index.ts +0 -67
package/utils.ts
CHANGED
|
@@ -1,6 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const adjectives = [
|
|
2
|
+
'agile',
|
|
3
|
+
'bold',
|
|
4
|
+
'calm',
|
|
5
|
+
'deft',
|
|
6
|
+
'easy',
|
|
7
|
+
'fair',
|
|
8
|
+
'glad',
|
|
9
|
+
'hale',
|
|
10
|
+
'idle',
|
|
11
|
+
'just',
|
|
12
|
+
'keen',
|
|
13
|
+
'lush',
|
|
14
|
+
'mild',
|
|
15
|
+
'neat',
|
|
16
|
+
'open',
|
|
17
|
+
'pale',
|
|
18
|
+
'rare',
|
|
19
|
+
'safe',
|
|
20
|
+
'tall',
|
|
21
|
+
'vast',
|
|
22
|
+
'warm',
|
|
23
|
+
'zany',
|
|
24
|
+
'able',
|
|
25
|
+
'blue',
|
|
26
|
+
'cool',
|
|
27
|
+
'dark',
|
|
28
|
+
'even',
|
|
29
|
+
'fast',
|
|
30
|
+
'good',
|
|
31
|
+
'high',
|
|
32
|
+
'kind',
|
|
33
|
+
'lean',
|
|
34
|
+
'long',
|
|
35
|
+
'next',
|
|
36
|
+
'pink',
|
|
37
|
+
'real',
|
|
38
|
+
'slim',
|
|
39
|
+
'true',
|
|
40
|
+
'wide',
|
|
41
|
+
'zero'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const nouns = [
|
|
45
|
+
'ant',
|
|
46
|
+
'bee',
|
|
47
|
+
'cat',
|
|
48
|
+
'dog',
|
|
49
|
+
'elk',
|
|
50
|
+
'fox',
|
|
51
|
+
'gnu',
|
|
52
|
+
'hen',
|
|
53
|
+
'ibis',
|
|
54
|
+
'jay',
|
|
55
|
+
'koi',
|
|
56
|
+
'lynx',
|
|
57
|
+
'moth',
|
|
58
|
+
'newt',
|
|
59
|
+
'owl',
|
|
60
|
+
'puma',
|
|
61
|
+
'quail',
|
|
62
|
+
'ram',
|
|
63
|
+
'seal',
|
|
64
|
+
'toad',
|
|
65
|
+
'urchin',
|
|
66
|
+
'vole',
|
|
67
|
+
'wolf',
|
|
68
|
+
'yak',
|
|
69
|
+
'ape',
|
|
70
|
+
'bass',
|
|
71
|
+
'crow',
|
|
72
|
+
'dove',
|
|
73
|
+
'eel',
|
|
74
|
+
'frog',
|
|
75
|
+
'goat',
|
|
76
|
+
'hawk',
|
|
77
|
+
'ibex',
|
|
78
|
+
'lark',
|
|
79
|
+
'mole',
|
|
80
|
+
'oryx',
|
|
81
|
+
'pike',
|
|
82
|
+
'rook',
|
|
83
|
+
'swan',
|
|
84
|
+
'wren'
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
function pick<T>(arr: T[]): T {
|
|
88
|
+
const index = Math.floor(Math.random() * arr.length)
|
|
89
|
+
if (!arr[index]) {
|
|
90
|
+
throw new Error('Array is empty')
|
|
91
|
+
}
|
|
92
|
+
return arr[index]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Generate a human-readable unique identifier, e.g. "bold-calm-fox" */
|
|
96
|
+
export function uid(): string {
|
|
97
|
+
return `${pick(adjectives)}-${pick(adjectives)}-${pick(nouns)}`
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Open a URL in the default browser using platform-native commands */
|
|
101
|
+
export function openBrowser(url: string): void {
|
|
102
|
+
const cmds: Record<string, string[]> = {
|
|
103
|
+
darwin: ['open', url],
|
|
104
|
+
win32: ['cmd', '/c', 'start', url]
|
|
105
|
+
}
|
|
106
|
+
const args = cmds[process.platform] ?? ['xdg-open', url]
|
|
107
|
+
Bun.spawn(args, { stdio: ['ignore', 'ignore', 'ignore'] })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Encode an ArrayBuffer to base64 */
|
|
111
|
+
export function toBase64(buf: ArrayBuffer): string {
|
|
112
|
+
return Buffer.from(buf).toString('base64')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Decode a base64 string to a Uint8Array */
|
|
116
|
+
export function fromBase64(str: string): Uint8Array<ArrayBuffer> {
|
|
117
|
+
const buf = Buffer.from(str, 'base64')
|
|
118
|
+
return new Uint8Array(buf.buffer as ArrayBuffer, buf.byteOffset, buf.byteLength)
|
|
119
|
+
}
|
package/bun.lockb
DELETED
|
Binary file
|
package/fly.toml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
|
2
|
-
|
|
3
|
-
app = 'tunnel'
|
|
4
|
-
primary_region = 'yul'
|
|
5
|
-
|
|
6
|
-
[build]
|
|
7
|
-
|
|
8
|
-
[http_service]
|
|
9
|
-
internal_port = 1234
|
|
10
|
-
force_https = false
|
|
11
|
-
auto_stop_machines = "suspend"
|
|
12
|
-
auto_start_machines = true
|
|
13
|
-
min_machines_running = 0
|
|
14
|
-
processes = ['app']
|
|
15
|
-
|
|
16
|
-
[[vm]]
|
|
17
|
-
memory = '1gb'
|
|
18
|
-
cpu_kind = 'shared'
|
|
19
|
-
cpus = 1
|
package/index.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import "localenv";
|
|
2
|
-
import optimist from "optimist";
|
|
3
|
-
import Debug from "debug";
|
|
4
|
-
import { CreateServer } from "./server";
|
|
5
|
-
import { type AddressInfo } from "ws";
|
|
6
|
-
|
|
7
|
-
const debug = Debug("localtunnel");
|
|
8
|
-
|
|
9
|
-
const argv = optimist
|
|
10
|
-
.usage("Usage: $0 --port [num]")
|
|
11
|
-
.options("secure", {
|
|
12
|
-
default: false,
|
|
13
|
-
describe: "use this flag to indicate proxy over https",
|
|
14
|
-
})
|
|
15
|
-
.options("port", {
|
|
16
|
-
default: "80",
|
|
17
|
-
describe: "listen on this port for outside requests",
|
|
18
|
-
})
|
|
19
|
-
.options("address", {
|
|
20
|
-
default: "0.0.0.0",
|
|
21
|
-
describe: "IP address to bind to",
|
|
22
|
-
})
|
|
23
|
-
.options("domain", {
|
|
24
|
-
describe:
|
|
25
|
-
"Specify the base domain name. This is optional if hosting localtunnel from a regular example.com domain. This is required if hosting a localtunnel server from a subdomain (i.e. lt.example.dom where clients will be client-app.lt.example.come)",
|
|
26
|
-
})
|
|
27
|
-
.options("max-sockets", {
|
|
28
|
-
default: 10,
|
|
29
|
-
describe:
|
|
30
|
-
"maximum number of tcp sockets each client is allowed to establish at one time (the tunnels)",
|
|
31
|
-
}).argv;
|
|
32
|
-
|
|
33
|
-
if (argv.help) {
|
|
34
|
-
console.log("Showing help");
|
|
35
|
-
optimist.showHelp();
|
|
36
|
-
process.exit();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const server = CreateServer({
|
|
40
|
-
max_tcp_sockets: argv["max-sockets"],
|
|
41
|
-
secure: argv.secure,
|
|
42
|
-
domain: argv.domain,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
server.listen(argv.port, argv.address, () => {
|
|
46
|
-
debug("server listening on port: %d", (server.address() as AddressInfo).port);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
process.on("SIGINT", () => {
|
|
50
|
-
console.error("SIGINT");
|
|
51
|
-
process.exit();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
process.on("SIGTERM", () => {
|
|
55
|
-
console.warn("SIGTERM");
|
|
56
|
-
// process.exit();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
process.on("uncaughtException", (err) => {
|
|
60
|
-
console.error("err:");
|
|
61
|
-
console.error(err);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
process.on("unhandledRejection", (reason, promise) => {
|
|
65
|
-
console.error("reason:");
|
|
66
|
-
console.error(reason);
|
|
67
|
-
});
|