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
@@ -1150,7 +1150,7 @@ Set by Docker. Node identity in metrics and logs.
|
|||||||
|
|
||||||
#### `FLUXER_ENV`
|
#### `FLUXER_ENV`
|
||||||
|
|
||||||
Default `development`. The runtime mode. `development`, `production`, or `test`. Compose pins `production`, which gates Postgres validation and the admin cookie flags. On a self-hosted instance, `production` also enforces the [setup token](#setup-token).
|
Default `production` when `FLUXER_SELF_HOSTED` is `true`, otherwise `development`. The runtime mode. `development`, `production`, or `test`. Compose pins `production`, which gates Postgres validation and the admin cookie flags. On a self-hosted instance, `production` also enforces the [setup token](#setup-token).
|
||||||
|
|
||||||
#### `FLUXER_SELF_HOSTED`
|
#### `FLUXER_SELF_HOSTED`
|
||||||
|
|
||||||
|
|||||||
@@ -665,6 +665,13 @@ function normalizeConfig(config: MasterConfig): MasterConfig {
|
|||||||
return config;
|
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 {
|
function applyPublicOrigin(config: MasterConfig): MasterConfig {
|
||||||
const raw = config.domain.public_origin;
|
const raw = config.domain.public_origin;
|
||||||
if (raw.trim().length === 0 && !/\p{Cc}/u.test(raw)) {
|
if (raw.trim().length === 0 && !/\p{Cc}/u.test(raw)) {
|
||||||
@@ -787,7 +794,10 @@ export async function loadConfig(): Promise<MasterConfig> {
|
|||||||
return cachedConfig;
|
return cachedConfig;
|
||||||
}
|
}
|
||||||
const overrides = buildNamedFluxerEnvOverrides(process.env);
|
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 normalized = normalizeConfig(merged);
|
||||||
const derived = deriveEndpointsFromDomain(normalized.domain);
|
const derived = deriveEndpointsFromDomain(normalized.domain);
|
||||||
const endpoints = {...derived, ...(normalized.endpoint_overrides ?? {})};
|
const endpoints = {...derived, ...(normalized.endpoint_overrides ?? {})};
|
||||||
|
|||||||
@@ -80,6 +80,29 @@ describe('ConfigLoader', () => {
|
|||||||
expect((await loadConfig()).domain.base_domain).toBe('localhost');
|
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 () => {
|
test('endpoint overrides take precedence over derived endpoints', async () => {
|
||||||
stubMinimalEnv({
|
stubMinimalEnv({
|
||||||
FLUXER_API_ENDPOINT: 'https://custom-api.example.com',
|
FLUXER_API_ENDPOINT: 'https://custom-api.example.com',
|
||||||
|
|||||||
Reference in new issue
Block a user