mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(config): default self-hosted instances to production (#3470)
This commit is contained in:
1 parent
8c05497c37
commit
5f5e26a8d4
3 files changed
+35
-2
No files matched your search
@@ -665,6 +665,13 @@ function normalizeConfig(config: MasterConfig): MasterConfig {
|
||||
return config;
|
||||
}
|
||||
|
||||
function applySelfHostedEnvDefault(config: MasterConfig, explicitEnv: string | undefined): MasterConfig {
|
||||
if (explicitEnv !== undefined || !config.instance.self_hosted) {
|
||||
return config;
|
||||
}
|
||||
return {...config, env: 'production'};
|
||||
}
|
||||
|
||||
function applyPublicOrigin(config: MasterConfig): MasterConfig {
|
||||
const raw = config.domain.public_origin;
|
||||
if (raw.trim().length === 0 && !/\p{Cc}/u.test(raw)) {
|
||||
@@ -787,7 +794,10 @@ export async function loadConfig(): Promise<MasterConfig> {
|
||||
return cachedConfig;
|
||||
}
|
||||
const overrides = buildNamedFluxerEnvOverrides(process.env);
|
||||
const merged = applyPublicOrigin(mergeConfig(defaultConfig(), overrides));
|
||||
const merged = applySelfHostedEnvDefault(
|
||||
applyPublicOrigin(mergeConfig(defaultConfig(), overrides)),
|
||||
readEnvValue(process.env, 'FLUXER_ENV'),
|
||||
);
|
||||
const normalized = normalizeConfig(merged);
|
||||
const derived = deriveEndpointsFromDomain(normalized.domain);
|
||||
const endpoints = {...derived, ...(normalized.endpoint_overrides ?? {})};
|
||||
|
||||
@@ -80,6 +80,29 @@ describe('ConfigLoader', () => {
|
||||
expect((await loadConfig()).domain.base_domain).toBe('localhost');
|
||||
});
|
||||
|
||||
test('a self-hosted instance without FLUXER_ENV runs in production', async () => {
|
||||
stubMinimalEnv({
|
||||
FLUXER_SELF_HOSTED: 'true',
|
||||
FLUXER_PROFILE_PSEUDONYM_SECRET: 'self-hosted-secret',
|
||||
FLUXER_POSTGRES_HOST: 'postgres',
|
||||
FLUXER_POSTGRES_DATABASE: 'fluxer',
|
||||
FLUXER_POSTGRES_PASSWORD: 'self-hosted-password',
|
||||
});
|
||||
vi.stubEnv('FLUXER_ENV', undefined);
|
||||
expect((await loadConfig()).env).toBe('production');
|
||||
});
|
||||
|
||||
test('a self-hosted instance keeps an explicit FLUXER_ENV', async () => {
|
||||
stubMinimalEnv({FLUXER_SELF_HOSTED: 'true', FLUXER_ENV: 'development'});
|
||||
expect((await loadConfig()).env).toBe('development');
|
||||
});
|
||||
|
||||
test('an instance that is not self-hosted still defaults to development', async () => {
|
||||
stubMinimalEnv();
|
||||
vi.stubEnv('FLUXER_ENV', undefined);
|
||||
expect((await loadConfig()).env).toBe('development');
|
||||
});
|
||||
|
||||
test('endpoint overrides take precedence over derived endpoints', async () => {
|
||||
stubMinimalEnv({
|
||||
FLUXER_API_ENDPOINT: 'https://custom-api.example.com',
|
||||
|
||||
Reference in new issue
Block a user