-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathworkerToken.ts
More file actions
29 lines (25 loc) · 736 Bytes
/
workerToken.ts
File metadata and controls
29 lines (25 loc) · 736 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
import { readFileSync } from "fs";
import { env } from "./env.js";
export function getWorkerToken() {
if (!env.TRIGGER_WORKER_TOKEN.startsWith("file://")) {
return env.TRIGGER_WORKER_TOKEN;
}
const tokenPath = env.TRIGGER_WORKER_TOKEN.replace("file://", "");
console.debug(
JSON.stringify({
message: "🔑 Reading worker token from file",
tokenPath,
})
);
try {
const token = readFileSync(tokenPath, "utf8").trim();
return token;
} catch (error) {
console.error(`Failed to read worker token from file: ${tokenPath}`, error);
throw new Error(
`Unable to read worker token from file: ${
error instanceof Error ? error.message : "Unknown error"
}`
);
}
}