47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { existsSync } from 'node:fs';
|
|
import { resolve } from 'node:path';
|
|
import { loadEnvFile } from 'node:process';
|
|
|
|
for (const directory of [
|
|
process.cwd(),
|
|
resolve(process.cwd(), '..'),
|
|
resolve(process.cwd(), '../..'),
|
|
]) {
|
|
const path = resolve(directory, '.env');
|
|
if (existsSync(path)) {
|
|
loadEnvFile(path);
|
|
break;
|
|
}
|
|
}
|
|
|
|
function required(name: string): string {
|
|
const value = process.env[name];
|
|
if (!value) throw new Error(`${name} is required`);
|
|
return value;
|
|
}
|
|
|
|
function objectStorageCredential(
|
|
accessKeyName: string,
|
|
localFallbackName: string,
|
|
): string {
|
|
return process.env[accessKeyName] || required(localFallbackName);
|
|
}
|
|
|
|
export const workerConfig = {
|
|
databaseUrl: required('DATABASE_URL'),
|
|
redisUrl: required('REDIS_URL'),
|
|
storeSecretEncryptionKey: required('STORE_SECRET_ENCRYPTION_KEY'),
|
|
objectStorageEndpoint:
|
|
process.env.OBJECT_STORAGE_ENDPOINT ?? 'http://localhost:9000',
|
|
objectStorageForcePathStyle:
|
|
(process.env.OBJECT_STORAGE_FORCE_PATH_STYLE ?? 'true') === 'true',
|
|
objectStorageAccessKey: objectStorageCredential(
|
|
'OBJECT_STORAGE_ACCESS_KEY',
|
|
'MINIO_ROOT_USER',
|
|
),
|
|
objectStorageSecretKey: objectStorageCredential(
|
|
'OBJECT_STORAGE_SECRET_KEY',
|
|
'MINIO_ROOT_PASSWORD',
|
|
),
|
|
};
|