Skip to content

Commit 8fda8a4

Browse files
authored
chore(scripts): add ping actor script (#3277)
1 parent 1a6b2a5 commit 8fda8a4

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

scripts/api/gateway/ping-actor.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env tsx
2+
3+
import * as readline from "readline/promises";
4+
5+
const rl = readline.createInterface({
6+
input: process.stdin,
7+
output: process.stdout,
8+
});
9+
10+
const endpoint =
11+
process.env.RIVET_ENDPOINT ||
12+
(await rl.question("Endpoint (default: api.rivet.dev): ")).trim() ||
13+
"api.rivet.dev";
14+
15+
const rivetToken =
16+
process.env.RIVET_TOKEN ||
17+
(await rl.question("Rivet Token: ")).trim();
18+
19+
if (!rivetToken) {
20+
console.error("Error: Rivet Token is required");
21+
process.exit(1);
22+
}
23+
24+
const actorId = (await rl.question("Actor ID: ")).trim();
25+
26+
if (!actorId) {
27+
console.error("Error: Actor ID is required");
28+
process.exit(1);
29+
}
30+
31+
rl.close();
32+
33+
const url = endpoint.startsWith("http") ? endpoint : `https://${endpoint}`;
34+
35+
// Print equivalent curl command
36+
console.log("Equivalent curl command:");
37+
console.log(
38+
`curl -H "x-rivet-target: actor" -H "x-rivet-actor: ${actorId}" -H "x-rivet-token: ${rivetToken}" ${url}`,
39+
);
40+
console.log();
41+
42+
const response = await fetch(url, {
43+
method: "GET",
44+
headers: {
45+
"x-rivet-target": "actor",
46+
"x-rivet-actor": actorId,
47+
"x-rivet-token": rivetToken,
48+
},
49+
});
50+
51+
if (!response.ok) {
52+
console.error(`Error: ${response.status} ${response.statusText}`);
53+
console.error(await response.text());
54+
process.exit(1);
55+
}
56+
57+
const data = await response.text();
58+
59+
console.log(data);

0 commit comments

Comments
 (0)