From ff708f5f207b0999af31cc79e350159ec073e0dc Mon Sep 17 00:00:00 2001 From: dec0dOS Date: Tue, 9 Jul 2024 16:18:52 +0100 Subject: [PATCH] chore: improve error handler for token --- backend/utils/controller-api.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/utils/controller-api.js b/backend/utils/controller-api.js index 8bdbfe3..028a081 100644 --- a/backend/utils/controller-api.js +++ b/backend/utils/controller-api.js @@ -1,13 +1,16 @@ import axios from "axios"; import fs from "node:fs"; +import os from "node:os"; const baseURL = process.env.ZU_CONTROLLER_ENDPOINT || "http://localhost:9993/"; var token; if (process.env.ZU_CONTROLLER_TOKEN) { token = process.env.ZU_CONTROLLER_TOKEN; -} else { +} else if (os.platform() === "linux") { token = fs.readFileSync("/var/lib/zerotier-one/authtoken.secret", "utf8"); +} else { + throw new Error("Please provide ZU_CONTROLLER_TOKEN in environment"); } export const api = axios.create({