diff --git a/server/auth.js b/server/auth.js index 82fe659..47748bb 100644 --- a/server/auth.js +++ b/server/auth.js @@ -15,14 +15,14 @@ const crypto = require('crypto'); const fs = require('fs'); -const os = require('os'); const path = require('path'); const config = require('./config'); +const { resolveCcxrayHome } = require('./paths'); // ─── Root secret resolution ────────────────────────────────────────── function getHubDir() { - return process.env.CCXRAY_HOME || path.join(os.homedir(), '.ccxray'); + return resolveCcxrayHome(); } function ensureHubDir() { diff --git a/server/hub.js b/server/hub.js index 248bcd0..ad17d13 100644 --- a/server/hub.js +++ b/server/hub.js @@ -2,11 +2,11 @@ const fs = require('fs'); const path = require('path'); -const os = require('os'); const net = require('net'); const http = require('http'); +const { resolveCcxrayHome } = require('./paths'); -const HUB_DIR = process.env.CCXRAY_HOME || path.join(os.homedir(), '.ccxray'); +const HUB_DIR = resolveCcxrayHome(); const HUB_LOCK_PATH = path.join(HUB_DIR, 'hub.json'); const HUB_LOG_PATH = path.join(HUB_DIR, 'hub.log'); const SOCK_PATH = path.join(HUB_DIR, 'hub.sock'); diff --git a/server/paths.js b/server/paths.js index 14e2870..62fcf68 100644 --- a/server/paths.js +++ b/server/paths.js @@ -3,12 +3,11 @@ const path = require('path'); const os = require('os'); -// Single source of truth for ccxray's on-disk locations. config.js and -// storage/index.js both resolve the logs dir from here, so the startup banner -// and legacy-migration target can no longer drift from where logs actually -// get written. hub.js, settings.js, ratelimit-log.js, and auth.js still -// duplicate the home-dir resolution inline and are candidates for future -// consolidation here. +// Single source of truth for ccxray's on-disk locations. config.js, +// storage/index.js, hub.js, settings.js, ratelimit-log.js, and auth.js all +// resolve their ccxray home/logs paths from here, so the startup banner, +// legacy-migration target, and every other consumer stay in sync and can no +// longer drift from where logs actually get written. // // Precedence (mirrors the storage adapter's historical resolution): // logs dir : LOGS_DIR > /logs diff --git a/server/ratelimit-log.js b/server/ratelimit-log.js index 78bf50c..632db59 100644 --- a/server/ratelimit-log.js +++ b/server/ratelimit-log.js @@ -1,14 +1,14 @@ 'use strict'; const fs = require('fs'); -const os = require('os'); const path = require('path'); +const { resolveCcxrayHome } = require('./paths'); // Append-only log of `anthropic-ratelimit-*` headers observed from upstream responses. // Used for future calibration of plan-specific limits (Max 5x vs 20x tokens5h quota). // File: ~/.ccxray/ratelimit-samples.jsonl (respects CCXRAY_HOME env) -const CCXRAY_HOME = process.env.CCXRAY_HOME || path.join(os.homedir(), '.ccxray'); +const CCXRAY_HOME = resolveCcxrayHome(); const SAMPLES_FILE = path.join(CCXRAY_HOME, 'ratelimit-samples.jsonl'); // Dedupe per model: skip writing if headers identical to last sample for diff --git a/server/settings.js b/server/settings.js index 2e320d7..114c670 100644 --- a/server/settings.js +++ b/server/settings.js @@ -2,9 +2,9 @@ const fs = require('fs'); const path = require('path'); -const os = require('os'); +const { resolveCcxrayHome } = require('./paths'); -const SETTINGS_DIR = process.env.CCXRAY_HOME || path.join(os.homedir(), '.ccxray'); +const SETTINGS_DIR = resolveCcxrayHome(); const SETTINGS_PATH = path.join(SETTINGS_DIR, 'settings.json'); const DEFAULTS = {