Skip to content

Commit dce2df6

Browse files
refactor: replace implicit global config with explicit global.config (#4085)
In PR #4072 the GitHub bot complained about a missing variable declaration for `config` in `app.js` and suggested adding `let config`. Applying that suggestion broke the app because `server_functions.js` was accessing `config` as an implicit global variable - the `let` declaration made it unreachable from there. So instead of the `let` declaration, I replaced all bare `config` references with explicit `global.config`. This makes the dependency on the global variable visible without changing runtime behavior, consistent with how other globals like `global.root_path` and `global.version` are already handled throughout the codebase. Related to #4073
1 parent 19c6489 commit dce2df6

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

js/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ function App () {
174174
*/
175175
this.start = async function () {
176176
const configObj = Utils.loadConfig();
177-
config = configObj.fullConf;
177+
global.config = configObj.fullConf;
178+
const config = global.config;
178179
Utils.checkConfigFile(configObj);
179180

180181
global.defaultModulesDir = config.defaultModulesDir;
@@ -245,7 +246,7 @@ function App () {
245246

246247
Log.log("Sockets connected & modules started ...");
247248

248-
return config;
249+
return global.config;
249250
};
250251

251252
/**

js/server_functions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function cors (req, res) {
4646
return res.status(400).send(url);
4747
} else {
4848
url = match[1];
49-
if (typeof config !== "undefined") {
49+
if (typeof global.config !== "undefined") {
5050
if (config.hideConfigSecrets) {
5151
url = replaceSecretPlaceholder(url);
5252
}
@@ -144,15 +144,15 @@ function getVersion (req, res) {
144144
function getUserAgent () {
145145
const defaultUserAgent = `Mozilla/5.0 (Node.js ${Number(process.version.match(/^v(\d+\.\d+)/)[1])}) MagicMirror/${global.version}`;
146146

147-
if (typeof config === "undefined") {
147+
if (typeof global.config === "undefined") {
148148
return defaultUserAgent;
149149
}
150150

151-
switch (typeof config.userAgent) {
151+
switch (typeof global.config.userAgent) {
152152
case "function":
153-
return config.userAgent();
153+
return global.config.userAgent();
154154
case "string":
155-
return config.userAgent;
155+
return global.config.userAgent;
156156
default:
157157
return defaultUserAgent;
158158
}
@@ -163,7 +163,7 @@ function getUserAgent () {
163163
* @returns {object} environment variables key: values
164164
*/
165165
function getEnvVarsAsObj () {
166-
const obj = { modulesDir: `${config.foreignModulesDir}`, defaultModulesDir: `${config.defaultModulesDir}`, customCss: `${config.customCss}` };
166+
const obj = { modulesDir: `${global.config.foreignModulesDir}`, defaultModulesDir: `${global.config.defaultModulesDir}`, customCss: `${global.config.customCss}` };
167167
if (process.env.MM_MODULES_DIR) {
168168
obj.modulesDir = process.env.MM_MODULES_DIR.replace(`${global.root_path}/`, "");
169169
}

0 commit comments

Comments
 (0)