Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ function getOption(
return env;
}

/**
* Parse a boolean-like environment variable.
* Returns `true` for 1/true/yes/y, `false` for 0/false/no/n, and
* `undefined` if the variable is not set or unrecognized.
*/
function getBooleanOption(
envName: string,
required: boolean = true,
): boolean | undefined {
const val = getOption(envName, required);
if (val === undefined) return undefined;
const v = val.trim().toLowerCase();
if (["1", "true", "yes", "y"].includes(v)) return true;
if (["0", "false", "no", "n"].includes(v)) return false;
return undefined;
}

// Pass --options via CLI arguments in command to enable these options.
const options: AppOptions = {
// Launching lots of services on the server,
Expand All @@ -49,14 +66,7 @@ const options: AppOptions = {
// mongoUri: getOption("MONGO_URI")!,
authDiscoveryURL: getOption("AUTH_DISCOVERY_URL")!,
authClientID: getOption("AUTH_CLIENT_ID")!,
authSkip: (() => {
const opt = getOption("AUTH_SKIP", false);
if (opt !== undefined) {
return Boolean(opt);
} else {
return undefined;
}
})(),
authSkip: getBooleanOption("AUTH_SKIP", false),
};

// Support Typebox
Expand Down