Files
drop/server/internal/config/sys-conf.ts
Husky 73c27f0984 User invite uses external domain option (#118)
* feat: user invite uses external domain option
fixes #117

* fix: inconsistent external url format

* fix: normalize external url more cleanly
2025-07-01 09:11:26 +10:00

72 lines
1.6 KiB
TypeScript

import normalizeUrl from "normalize-url";
class SystemConfig {
private libraryFolder = process.env.LIBRARY ?? "./.data/library";
private dataFolder = process.env.DATA ?? "./.data/data";
private externalUrl = normalizeUrl(
process.env.EXTERNAL_URL ?? "http://localhost:3000",
{ stripWWW: false },
);
private dropVersion;
private gitRef;
private checkForUpdates = getUpdateCheckConfig();
constructor() {
// get drop version and git ref from nuxt config
const config = useRuntimeConfig();
this.dropVersion = config.dropVersion;
this.gitRef = config.gitRef;
}
getLibraryFolder() {
return this.libraryFolder;
}
getDataFolder() {
return this.dataFolder;
}
getDropVersion() {
return this.dropVersion;
}
getGitRef() {
return this.gitRef;
}
shouldCheckForUpdates() {
return this.checkForUpdates;
}
getExternalUrl() {
return this.externalUrl;
}
}
export const systemConfig = new SystemConfig();
/**
* Gets the configuration for checking updates based on various conditions
* @returns true if updates should be checked, false otherwise.
*/
function getUpdateCheckConfig(): boolean {
const envCheckUpdates = process.env.CHECK_FOR_UPDATES;
// Check environment variable
if (envCheckUpdates !== undefined) {
// if explicitly set to true or false, return that value
if (envCheckUpdates.toLocaleLowerCase() === "true") {
return true;
} else if (envCheckUpdates.toLocaleLowerCase() === "false") {
return false;
}
} else if (process.env.NODE_ENV === "production") {
// default to true in production
return true;
}
return false;
}