mirror of
https://github.com/immich-app/immich.git
synced 2026-03-08 02:57:48 +03:00
refactor(server): env validation (#13817)
This commit is contained in:
@@ -8,6 +8,7 @@ const getEnv = () => {
|
||||
|
||||
const resetEnv = () => {
|
||||
for (const env of [
|
||||
'IMMICH_ENV',
|
||||
'IMMICH_WORKERS_INCLUDE',
|
||||
'IMMICH_WORKERS_EXCLUDE',
|
||||
'IMMICH_TRUSTED_PROXIES',
|
||||
@@ -62,6 +63,18 @@ describe('getEnv', () => {
|
||||
resetEnv();
|
||||
});
|
||||
|
||||
it('should use defaults', () => {
|
||||
const config = getEnv();
|
||||
|
||||
expect(config).toMatchObject({
|
||||
host: undefined,
|
||||
port: 2283,
|
||||
environment: 'production',
|
||||
configFile: undefined,
|
||||
logLevel: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
describe('database', () => {
|
||||
it('should use defaults', () => {
|
||||
const { database } = getEnv();
|
||||
@@ -202,6 +215,11 @@ describe('getEnv', () => {
|
||||
trustedProxies: ['10.1.0.0', '10.2.0.0', '169.254.0.0/16'],
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject invalid trusted proxies', () => {
|
||||
process.env.IMMICH_TRUSTED_PROXIES = '10.1';
|
||||
expect(() => getEnv()).toThrowError('Invalid environment variables: IMMICH_TRUSTED_PROXIES');
|
||||
});
|
||||
});
|
||||
|
||||
describe('telemetry', () => {
|
||||
|
||||
Reference in New Issue
Block a user