Skip to content

best way to save what you love

api: alias deprecated envs to maintain backwards compatibility

dumbmoron12833e18270f
diff --git a/src/cobalt.js b/src/cobalt.js
index 40bca04b..050aec46 100644
--- a/src/cobalt.js
+++ b/src/cobalt.js
@@ -1,4 +1,5 @@
import "dotenv/config";
+import "./modules/sub/alias-envs.js";
import express from "express";
diff --git a/src/modules/sub/alias-envs.js b/src/modules/sub/alias-envs.js
new file mode 100644
index 00000000..6cf775ef
--- /dev/null
+++ b/src/modules/sub/alias-envs.js
@@ -0,0 +1,22 @@
+import { Red } from "./consoleText.js";
+
+const mapping = {
+ apiPort: 'API_PORT',
+ apiURL: 'API_URL',
+ apiName: 'API_NAME',
+ cors: 'CORS_WILDCARD',
+ cookiePath: 'COOKIE_PATH',
+ webPort: 'WEB_PORT',
+ webUrl: 'WEB_URL',
+ showSponsors: 'SHOW_SPONSORS',
+ isBeta: 'IS_BETA'
+}
+
+for (const [ oldEnv, newEnv ] of Object.entries(mapping)) {
+ if (process.env[oldEnv] && !process.env[newEnv]) {
+ process.env[newEnv] = process.env[oldEnv];
+ console.error(`${Red('[!]')} ${oldEnv} is deprecated and will be removed in a future version.`);
+ console.error(` You should use ${newEnv} instead.`);
+ console.error();
+ }
+}