From e2ca3c5d1acb369129323dcb11c74960511064f5 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Sun, 14 Aug 2022 14:23:50 +0800 Subject: [PATCH] feat: add support to default authtoken location of major platforms Signed-off-by: Syrone Wong --- backend/utils/controller-api.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/utils/controller-api.js b/backend/utils/controller-api.js index 37f7338..4f102fb 100644 --- a/backend/utils/controller-api.js +++ b/backend/utils/controller-api.js @@ -7,7 +7,21 @@ var token; if (process.env.ZU_CONTROLLER_TOKEN) { token = process.env.ZU_CONTROLLER_TOKEN; } else { - token = fs.readFileSync("/var/lib/zerotier-one/authtoken.secret", "utf8"); + if (process.platform === "unix") { + token = fs.readFileSync("/var/lib/zerotier-one/authtoken.secret", "utf8"); + } else if (process.platform === "win32") { + token = fs.readFileSync( + "C:\\ProgramData\\ZeroTier\\One\\authtoken.secret", + "utf8" + ); + } else if (process.platform === "darwin") { + token = fs.readFileSync( + "/Library/Application Support/ZeroTier/One/authtoken.secret", + "utf8" + ); + } else { + throw `Unsupported platform ${process.platform}`; + } } module.exports = axios.create({