35 lines
1.4 KiB
JavaScript
35 lines
1.4 KiB
JavaScript
/**
|
|
* Environment variable loader from our env.json file (omitted from GitLab code export due to potential leakage
|
|
* of secrets). It is usually loaded at top of most of the functions and usually used at local development and
|
|
* when doing API development using Gitpod/containers.
|
|
*/
|
|
function loadEnvFromFile() {
|
|
const fs = require('fs');
|
|
|
|
fs.access("/opt/node_modules/autocode-common/configs", (err) => {
|
|
if (err) {
|
|
fs.access('env.json', (err) => {
|
|
/**
|
|
* If env.json exists locally, attempt to load them automagically within the Node.js process.
|
|
*/
|
|
const env = require("../env.json")
|
|
if (!err) {
|
|
process.env.MONGO_DATABASE = env.dev.MONGO_DATABASE
|
|
process.env.DISCORD_GUILD_ID = env.dev.DISCORD_GUILD_ID,
|
|
process.env.DISCORD_ROLE_ID = env.dev.DISCORD_GUILD_ID,
|
|
process.env.MW_OAUTH_CLIENT_ID = env.dev.MW_OAUTH_CLIENT_ID,
|
|
process.env.MW_OAUTH_CLIENT_SECRET = env.dev.MW_OAUTH_CLIENT_SECRET,
|
|
process.env.MW_MW_OAUTH_CALLBACK = env.dev.MW_OAUTH_CALLBACK,
|
|
process.env.MW_OAUTH_ROOT = env.dev.MW_OAUTH_ROOT
|
|
} else {
|
|
/** Otherwise, preload secrets using dotenv */
|
|
require("dotenv").config()
|
|
}
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
loadEnvFromFile
|
|
} |