-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathstart_dev.ts
More file actions
37 lines (28 loc) · 747 Bytes
/
start_dev.ts
File metadata and controls
37 lines (28 loc) · 747 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
30
31
32
33
34
35
36
37
const green = (text: string) => `\x1b[32m${text}\x1b[0m`;
async function tunnel() {
try {
const maxAttempts = 10;
let ngrok;
let attempts = 0;
while (attempts < maxAttempts) {
try {
ngrok = await fetch('http://localhost:4040/api/tunnels');
const { tunnels } = await ngrok.json();
console.log(green(tunnels[0].public_url));
break;
} catch {
attempts++;
await sleep(1000);
}
}
if (attempts >= maxAttempts) {
console.error('Failed to fetch ngrok tunnels after multiple attempts.');
}
} catch (err) {
console.error(err);
}
}
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
await tunnel();