Add frontend debug mode gate

This commit is contained in:
2026-05-11 18:00:36 +08:00
parent 928acb4302
commit 7cea41c911
7 changed files with 137 additions and 15 deletions

23
src/config/debugMode.ts Normal file
View File

@@ -0,0 +1,23 @@
const DEBUG_MODE_TRUE_VALUES = new Set(['1', 'true', 'yes', 'on']);
const DEBUG_MODE_FALSE_VALUES = new Set(['0', 'false', 'no', 'off']);
function parseOptionalBoolean(value: string | undefined) {
const normalizedValue = value?.trim().toLowerCase();
if (!normalizedValue) {
return null;
}
if (DEBUG_MODE_TRUE_VALUES.has(normalizedValue)) {
return true;
}
if (DEBUG_MODE_FALSE_VALUES.has(normalizedValue)) {
return false;
}
return null;
}
export const IS_DEBUG_MODE =
parseOptionalBoolean(import.meta.env.VITE_DEBUG_MODE) ?? import.meta.env.DEV;
export function isDebugMode() {
return IS_DEBUG_MODE;
}