mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add getEnv wrapper
This commit is contained in:
@@ -291,7 +291,7 @@ const typeMap: Record<string, string> = {
|
||||
let env: Record<string, any> = {
|
||||
...defaults,
|
||||
...process.env,
|
||||
...getEnv(),
|
||||
...processConfiguration(),
|
||||
};
|
||||
|
||||
process.env = env;
|
||||
@@ -300,6 +300,11 @@ env = processValues(env);
|
||||
|
||||
export default env;
|
||||
|
||||
/**
|
||||
* Small wrapper function that makes it easier to write unit tests against changing environments
|
||||
*/
|
||||
export const getEnv = () => env;
|
||||
|
||||
/**
|
||||
* When changes have been made during runtime, like in the CLI, we can refresh the env object with
|
||||
* the newly created variables
|
||||
@@ -308,7 +313,7 @@ export function refreshEnv(): void {
|
||||
env = {
|
||||
...defaults,
|
||||
...process.env,
|
||||
...getEnv(),
|
||||
...processConfiguration(),
|
||||
};
|
||||
|
||||
process.env = env;
|
||||
@@ -316,7 +321,7 @@ export function refreshEnv(): void {
|
||||
env = processValues(env);
|
||||
}
|
||||
|
||||
function getEnv() {
|
||||
function processConfiguration() {
|
||||
const configPath = path.resolve(process.env.CONFIG_PATH || defaults.CONFIG_PATH);
|
||||
|
||||
if (fs.existsSync(configPath) === false) return {};
|
||||
|
||||
Reference in New Issue
Block a user