MCPcopy
hub / github.com/NginxProxyManager/nginx-proxy-manager / configure

Function configure

backend/lib/config.js:17–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15// 1. Load from config file first (not recommended anymore)
16// 2. Use config env variables next
17const configure = () => {
18 const filename = `${process.env.NODE_CONFIG_DIR || "./config"}/${process.env.NODE_ENV || "default"}.json`;
19 if (fs.existsSync(filename)) {
20 let configData;
21 try {
22 // Load this json synchronously
23 const rawData = fs.readFileSync(filename);
24 configData = JSON.parse(rawData);
25 } catch (_) {
26 // do nothing
27 }
28
29 if (configData?.database) {
30 logger.info(`Using configuration from file: ${filename}`);
31
32 // Migrate those who have "mysql" engine to "mysql2"
33 if (configData.database.engine === "mysql") {
34 configData.database.engine = mysqlEngine;
35 }
36
37 instance = configData;
38 instance.keys = getKeys();
39 return;
40 }
41 }
42
43 const toBool = (v) => /^(1|true|yes|on)$/i.test((v || '').trim());
44
45 const envMysqlHost = process.env.DB_MYSQL_HOST || null;
46 const envMysqlUser = process.env.DB_MYSQL_USER || null;
47 const envMysqlName = process.env.DB_MYSQL_NAME || null;
48 const envMysqlSSL = toBool(process.env.DB_MYSQL_SSL);
49 const envMysqlSSLRejectUnauthorized = process.env.DB_MYSQL_SSL_REJECT_UNAUTHORIZED === undefined ? true : toBool(process.env.DB_MYSQL_SSL_REJECT_UNAUTHORIZED);
50 const envMysqlSSLVerifyIdentity = process.env.DB_MYSQL_SSL_VERIFY_IDENTITY === undefined ? true : toBool(process.env.DB_MYSQL_SSL_VERIFY_IDENTITY);
51 if (envMysqlHost && envMysqlUser && envMysqlName) {
52 // we have enough mysql creds to go with mysql
53 logger.info("Using MySQL configuration");
54 instance = {
55 database: {
56 engine: mysqlEngine,
57 host: envMysqlHost,
58 port: process.env.DB_MYSQL_PORT || 3306,
59 user: envMysqlUser,
60 password: process.env.DB_MYSQL_PASSWORD,
61 name: envMysqlName,
62 ssl: envMysqlSSL ? { rejectUnauthorized: envMysqlSSLRejectUnauthorized, verifyIdentity: envMysqlSSLVerifyIdentity } : false,
63 },
64 keys: getKeys(),
65 };
66 return;
67 }
68
69 const envPostgresHost = process.env.DB_POSTGRES_HOST || null;
70 const envPostgresUser = process.env.DB_POSTGRES_USER || null;
71 const envPostgresName = process.env.DB_POSTGRES_NAME || null;
72 if (envPostgresHost && envPostgresUser && envPostgresName) {
73 // we have enough postgres creds to go with postgres
74 logger.info("Using Postgres configuration");

Callers 7

configHasFunction · 0.85
configGetFunction · 0.85
isSqliteFunction · 0.85
isMysqlFunction · 0.85
isPostgresFunction · 0.85
getPublicKeyFunction · 0.85
getPrivateKeyFunction · 0.85

Calls 2

getKeysFunction · 0.85
toBoolFunction · 0.85

Tested by

no test coverage detected