fix: api key cache invalidated by config mtime - server picks up new key after reinstall
This commit is contained in:
@@ -15,11 +15,20 @@ function readApiKey() {
|
||||
}
|
||||
|
||||
let cachedApiKey = null;
|
||||
let cachedApiKeyMtime = 0;
|
||||
function getApiKey() {
|
||||
if (cachedApiKey === null) cachedApiKey = readApiKey();
|
||||
try {
|
||||
const stat = fs.statSync(CONFIG_PATH);
|
||||
if (cachedApiKeyMtime === stat.mtimeMs) return cachedApiKey;
|
||||
cachedApiKey = readApiKey();
|
||||
cachedApiKeyMtime = stat.mtimeMs;
|
||||
} catch {
|
||||
cachedApiKey = null;
|
||||
cachedApiKeyMtime = 0;
|
||||
}
|
||||
return cachedApiKey;
|
||||
}
|
||||
function clearApiKeyCache() { cachedApiKey = null; }
|
||||
function clearApiKeyCache() { cachedApiKey = null; cachedApiKeyMtime = 0; }
|
||||
|
||||
const xssOptions = {
|
||||
whiteList: {
|
||||
|
||||
Reference in New Issue
Block a user