best way to save what you love
Svelte collaborationdownloaderinstagramjavascriptmusicredditsocial-mediasoundcloudsveltetiktoktwittertypescriptvideovimeovkwebappyoutubeyoutube-downloader
env: readable environment variables in all files
wukkoe16ee6c1d32e
diff --git a/src/cobalt.js b/src/cobalt.jsindex 2d90e07e..40bca04b 100644--- a/src/cobalt.js+++ b/src/cobalt.js@@ -21,8 +21,8 @@ app.disable('x-powered-by');await loadLoc();-const apiMode = process.env.apiURL && !process.env.webURL;-const webMode = process.env.webURL && process.env.apiURL;+const apiMode = process.env.API_URL && !process.env.WEB_URL;+const webMode = process.env.WEB_URL && process.env.API_URL;if (apiMode) {const { runAPI } = await import('./core/api.js');diff --git a/src/core/api.js b/src/core/api.jsindex 5f910315..8e26dbd0 100644--- a/src/core/api.js+++ b/src/core/api.js@@ -14,7 +14,7 @@ import { sha256 } from "../modules/sub/crypto.js";import { verifyStream } from "../modules/stream/manage.js";export function runAPI(express, app, gitCommit, gitBranch, __dirname) {- const corsConfig = process.env.cors === '0' ? {+ const corsConfig = process.env.ENABLE_CORS === '0' ? {origin: process.env.CORS_URL,optionsSuccessStatus: 200} : {};@@ -141,9 +141,9 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {version: version,commit: gitCommit,branch: gitBranch,- name: process.env.apiName || "unknown",- url: process.env.apiURL,- cors: process.env?.cors === "0" ? 0 : 1,+ name: process.env.API_NAME || "unknown",+ url: process.env.API_URL,+ cors: process.env?.ENABLE_CORS === "0" ? 0 : 1,startTime: `${startTimestamp}`});default:@@ -169,12 +169,12 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {res.redirect('/api/json')});- app.listen(process.env.apiPort || 9000, () => {+ app.listen(process.env.API_PORT || 9000, () => {console.log(`\n` +`${Cyan("cobalt")} API ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +- `URL: ${Cyan(`${process.env.apiURL}`)}\n` +- `Port: ${process.env.apiPort || 9000}\n`+ `URL: ${Cyan(`${process.env.API_URL}`)}\n` ++ `Port: ${process.env.API_PORT || 9000}\n`)});}diff --git a/src/core/web.js b/src/core/web.jsindex 08a6ffed..7c0cbf33 100644--- a/src/core/web.js+++ b/src/core/web.js@@ -76,12 +76,12 @@ export async function runWeb(express, app, gitCommit, gitBranch, __dirname) {return res.redirect('/')});- app.listen(process.env.webPort || 9001, () => {+ app.listen(process.env.WEB_PORT || 9001, () => {console.log(`\n` +`${Cyan("cobalt")} WEB ${Bright(`v.${version}-${gitCommit} (${gitBranch})`)}\n` +`Start time: ${Bright(`${startTime.toUTCString()} (${startTimestamp})`)}\n\n` +- `URL: ${Cyan(`${process.env.webURL}`)}\n` +- `Port: ${process.env.webPort || 9001}\n`+ `URL: ${Cyan(`${process.env.WEB_URL}`)}\n` ++ `Port: ${process.env.WEB_PORT || 9001}\n`)})}diff --git a/src/modules/pageRender/elements.js b/src/modules/pageRender/elements.jsindex a677d2bc..53ad3c42 100644--- a/src/modules/pageRender/elements.js+++ b/src/modules/pageRender/elements.js@@ -264,5 +264,5 @@ export function sponsoredList() {}export function betaTag() {- return process.env.isBeta ? '<span class="logo-sub">β</span>' : ''+ return process.env.IS_BETA ? '<span class="logo-sub">β</span>' : ''}diff --git a/src/modules/pageRender/page.js b/src/modules/pageRender/page.jsindex 81e6d514..77b87f29 100644--- a/src/modules/pageRender/page.js+++ b/src/modules/pageRender/page.js@@ -48,10 +48,10 @@ export default function(obj) {<title>${t("AppTitleCobalt")}</title>- <meta property="og:url" content="${process.env.webURL}">+ <meta property="og:url" content="${process.env.WEB_URL}"><meta property="og:title" content="${t("AppTitleCobalt")}"><meta property="og:description" content="${t('EmbedBriefDescription')}">- <meta property="og:image" content="${process.env.webURL}icons/generic.png">+ <meta property="og:image" content="${process.env.WEB_URL}icons/generic.png"><meta name="title" content="${t("AppTitleCobalt")}"><meta name="description" content="${t('AboutSummary')}"><meta name="theme-color" content="#000000">@@ -165,7 +165,7 @@ export default function(obj) {body: t("FairUse")}])},- ...(process.env.showSponsors ?+ ...(process.env.SHOW_SPONSORS ?[{text: t("SponsoredBy"),classes: ["sponsored-by-text"],@@ -627,7 +627,7 @@ export default function(obj) {</footer></div><script>- let defaultApiUrl = '${process.env.apiURL ? process.env.apiURL : ''}';+ let defaultApiUrl = '${process.env.API_URL || ''}';const loc = ${webLoc(t,['ErrorNoInternet',diff --git a/src/modules/processing/cookie/manager.js b/src/modules/processing/cookie/manager.jsindex 7189eb18..a0b66f48 100644--- a/src/modules/processing/cookie/manager.js+++ b/src/modules/processing/cookie/manager.js@@ -3,7 +3,7 @@ import { readFile, writeFile } from 'fs/promises';import { parse as parseSetCookie, splitCookiesString } from 'set-cookie-parser';const WRITE_INTERVAL = 60000,- cookiePath = process.env.cookiePath,+ cookiePath = process.env.COOKIE_PATH,COUNTER = Symbol('counter');let cookies = {}, dirty = false, intervalId;diff --git a/src/modules/setup.js b/src/modules/setup.jsindex f81a0053..932cba57 100644--- a/src/modules/setup.js+++ b/src/modules/setup.js@@ -39,27 +39,27 @@ function setup() {console.log(Bright("\nCool! What's the domain this API instance will be running on? (localhost)\nExample: co.wuk.sh"));rl.question(q, apiURL => {- ob['apiURL'] = `http://localhost:9000/`;- ob['apiPort'] = 9000;- if (apiURL && apiURL !== "localhost") ob['apiURL'] = `https://${apiURL.toLowerCase()}/`;+ ob['API_URL'] = `http://localhost:9000/`;+ ob['API_PORT'] = 9000;+ if (apiURL && apiURL !== "localhost") ob['API_URL'] = `https://${apiURL.toLowerCase()}/`;console.log(Bright("\nGreat! Now, what port will it be running on? (9000)"));rl.question(q, apiPort => {- if (apiPort) ob['apiPort'] = apiPort;- if (apiPort && (apiURL === "localhost" || !apiURL)) ob['apiURL'] = `http://localhost:${apiPort}/`;+ if (apiPort) ob['API_PORT'] = apiPort;+ if (apiPort && (apiURL === "localhost" || !apiURL)) ob['API_URL'] = `http://localhost:${apiPort}/`;console.log(Bright("\nWhat will your instance's name be? Usually it's something like eu-nl aka region-country. (local)"));rl.question(q, apiName => {- ob['apiName'] = apiName.toLowerCase();- if (!apiName || apiName === "local") ob['apiName'] = "local";+ ob['API_URL'] = apiName.toLowerCase();+ if (!apiName || apiName === "local") ob['API_URL'] = "local";console.log(Bright("\nOne last thing: would you like to enable CORS? It allows other websites and extensions to use your instance's API.\ny/n (n)"));rl.question(q, apiCors => {let answCors = apiCors.toLowerCase().trim();- if (answCors !== "y" && answCors !== "yes") ob['cors'] = '0'+ if (answCors !== "y" && answCors !== "yes") ob['ENABLE_CORS'] = '0'final()})})@@ -71,25 +71,25 @@ function setup() {console.log(Bright("\nAwesome! What's the domain this web app instance will be running on? (localhost)\nExample: cobalt.tools"));rl.question(q, webURL => {- ob['webURL'] = `http://localhost:9001/`;- ob['webPort'] = 9001;- if (webURL && webURL !== "localhost") ob['webURL'] = `https://${webURL.toLowerCase()}/`;+ ob['WEB_URL'] = `http://localhost:9001/`;+ ob['WEB_PORT'] = 9001;+ if (webURL && webURL !== "localhost") ob['WEB_URL'] = `https://${webURL.toLowerCase()}/`;console.log(Bright("\nGreat! Now, what port will it be running on? (9001)"))rl.question(q, webPort => {- if (webPort) ob['webPort'] = webPort;- if (webPort && (webURL === "localhost" || !webURL)) ob['webURL'] = `http://localhost:${webPort}/`;+ if (webPort) ob['WEB_PORT'] = webPort;+ if (webPort && (webURL === "localhost" || !webURL)) ob['WEB_URL'] = `http://localhost:${webPort}/`;console.log(Bright("\nOne last thing: what default API domain should be used? (co.wuk.sh)\nIf it's hosted locally, make sure to include the port:") + Cyan(" localhost:9000"));rl.question(q, apiURL => {- ob['apiURL'] = `https://${apiURL.toLowerCase()}/`;- if (apiURL.includes(':')) ob['apiURL'] = `http://${apiURL.toLowerCase()}/`;- if (!apiURL) ob['apiURL'] = "https://co.wuk.sh/";+ ob['API_URL'] = `https://${apiURL.toLowerCase()}/`;+ if (apiURL.includes(':')) ob['API_URL'] = `http://${apiURL.toLowerCase()}/`;+ if (!apiURL) ob['API_URL'] = "https://co.wuk.sh/";final()})});diff --git a/src/modules/stream/manage.js b/src/modules/stream/manage.jsindex 459e5a6b..92a98da8 100644--- a/src/modules/stream/manage.js+++ b/src/modules/stream/manage.js@@ -43,7 +43,7 @@ export function createStream(obj) {exp = streamInfo.exp;ghmac = streamInfo.hmac;}- return `${process.env.apiURL}api/stream?t=${streamID}&e=${exp}&h=${ghmac}`;+ return `${process.env.API_URL}api/stream?t=${streamID}&e=${exp}&h=${ghmac}`;}export function verifyStream(id, hmac, exp) {