mirror of
https://github.com/directus/directus.git
synced 2026-01-25 22:18:25 -05:00
expanding function for envs
This commit is contained in:
@@ -37,7 +37,7 @@ function getRateLimiterConfig(): IRateLimiterOptions {
|
||||
|
||||
function getRateLimiterRedisConfig(): IRateLimiterStoreOptions {
|
||||
const redis = require('redis');
|
||||
const redisConfig: any = {};
|
||||
const redisConfig = parseEnv(0, 'redis');
|
||||
const redisClient = redis.createClient({
|
||||
enable_offline_queue: false,
|
||||
host: env.SREDIS_HOST,
|
||||
@@ -51,13 +51,5 @@ function getRateLimiterRedisConfig(): IRateLimiterStoreOptions {
|
||||
|
||||
redisConfig.storeClient = redisClient;
|
||||
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (key.startsWith('REDIS')) {
|
||||
// amended as we want the second and third words
|
||||
|
||||
redisConfig[parseEnv(key, 0)] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return redisConfig;
|
||||
}
|
||||
|
||||
@@ -19,22 +19,7 @@ registerDrivers(storage);
|
||||
export default storage;
|
||||
|
||||
function getStorageConfig(): StorageManagerConfig {
|
||||
const config: any = { disks: {} };
|
||||
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (key.startsWith('STORAGE') === false) continue;
|
||||
if (key === 'STORAGE_LOCATIONS') continue;
|
||||
if (key.endsWith('PUBLIC_URL')) continue;
|
||||
|
||||
const disk = key.split('_')[1].toLowerCase();
|
||||
if (!config.disks[disk]) config.disks[disk] = { config: {} };
|
||||
|
||||
if (key.endsWith('DRIVER')) {
|
||||
config.disks[disk].driver = value;
|
||||
continue;
|
||||
}
|
||||
config.disks[disk].config[parseEnv(key, 1)] = value;
|
||||
}
|
||||
const config = parseEnv(1, 'storage');
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,41 @@
|
||||
import camelcase from 'camelcase';
|
||||
import env from '../env';
|
||||
|
||||
export default function parseEnv(key: string, splitWord: number) {
|
||||
// splitWord 0 = exclude first word on _
|
||||
export default function parseEnv(splitWord: number, envType?: string) {
|
||||
// splitWord = where to spit the string to exlude any prewords
|
||||
const config: any = {};
|
||||
const storageConfig: any = { disks: {} };
|
||||
|
||||
const config = camelcase(
|
||||
key.split('_').filter((_, index) => [0, splitWord].includes(index) === false)
|
||||
);
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (envType === 'storage') {
|
||||
if (key.startsWith('STORAGE') === false) continue;
|
||||
if (key === 'STORAGE_LOCATIONS') continue;
|
||||
if (key.endsWith('PUBLIC_URL')) continue;
|
||||
|
||||
const disk = key.split('_')[1].toLowerCase();
|
||||
if (!storageConfig.disks[disk]) storageConfig.disks[disk] = { config: {} };
|
||||
|
||||
if (key.endsWith('DRIVER')) {
|
||||
storageConfig.disks[disk].driver = value;
|
||||
continue;
|
||||
}
|
||||
storageConfig.disks[disk].config[configCamel(key, splitWord)] = value;
|
||||
}
|
||||
if (envType === 'redis') {
|
||||
if (key.startsWith('REDIS')) {
|
||||
config[configCamel(key, splitWord)] = value;
|
||||
}
|
||||
} else {
|
||||
config[configCamel(key, splitWord)] = value;
|
||||
}
|
||||
}
|
||||
if (envType === 'storage') {
|
||||
return storageConfig;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function configCamel(key: string, sWord: number) {
|
||||
return camelcase(key.split('_').filter((_, index) => [0, sWord].includes(index) === false));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user