Fixed config path issue.
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
This commit is contained in:
parent
34ee72b19e
commit
d98140491f
@ -5,13 +5,16 @@ import { fileURLToPath } from "url";
|
||||
import log4js from "log4js";
|
||||
|
||||
// Determine environment
|
||||
const NODE_ENV = process.env.NODE_ENV || "development";
|
||||
|
||||
// Configure paths
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const isPackaged = __dirname.includes("app.asar");
|
||||
|
||||
const NODE_ENV =
|
||||
process.env.NODE_ENV || (isPackaged ? "production" : "development");
|
||||
|
||||
// Configure paths
|
||||
function getProductionConfigPath() {
|
||||
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
|
||||
switch (process.platform) {
|
||||
case "win32":
|
||||
return path.join(
|
||||
@ -20,19 +23,55 @@ function getProductionConfigPath() {
|
||||
"config.json"
|
||||
);
|
||||
case "darwin":
|
||||
// macOS standard for system-wide config is often /etc or /Library/Application Support
|
||||
// We'll stick to /etc as requested for parity with Linux
|
||||
return "/etc/farmcontrol-server/config.json";
|
||||
return path.join(
|
||||
homeDir,
|
||||
"Library",
|
||||
"Application Support",
|
||||
"farmcontrol-server",
|
||||
"config.json"
|
||||
);
|
||||
case "linux":
|
||||
default:
|
||||
return "/etc/farmcontrol-server/config.json";
|
||||
}
|
||||
}
|
||||
|
||||
function getDevelopmentConfigPath() {
|
||||
// If we're in a packaged app (asar), we can't write to the app directory.
|
||||
// We should use a writable user data directory instead.
|
||||
if (isPackaged) {
|
||||
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
|
||||
switch (process.platform) {
|
||||
case "win32":
|
||||
return path.join(
|
||||
process.env.APPDATA || path.join(homeDir, "AppData", "Roaming"),
|
||||
"farmcontrol-server",
|
||||
"config.json"
|
||||
);
|
||||
case "darwin":
|
||||
return path.join(
|
||||
homeDir,
|
||||
"Library",
|
||||
"Application Support",
|
||||
"farmcontrol-server",
|
||||
"config.json"
|
||||
);
|
||||
default:
|
||||
return path.join(
|
||||
homeDir,
|
||||
".config",
|
||||
"farmcontrol-server",
|
||||
"config.json"
|
||||
);
|
||||
}
|
||||
}
|
||||
return path.resolve(__dirname, "../config.json");
|
||||
}
|
||||
|
||||
const CONFIG_PATH =
|
||||
NODE_ENV === "production"
|
||||
? getProductionConfigPath()
|
||||
: path.resolve(__dirname, "../config.json");
|
||||
: getDevelopmentConfigPath();
|
||||
|
||||
const logger = log4js.getLogger("Config");
|
||||
logger.level = "info";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user