2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2017 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-03-12 16:35:52 +00:00
|
|
|
import { join, basename } from 'path';
|
2021-06-18 17:04:27 +00:00
|
|
|
import { app } from 'electron';
|
|
|
|
|
2021-10-01 18:49:59 +00:00
|
|
|
import type { IConfig } from 'config';
|
|
|
|
|
2021-06-18 17:04:27 +00:00
|
|
|
import {
|
2021-02-04 19:54:03 +00:00
|
|
|
Environment,
|
|
|
|
getEnvironment,
|
|
|
|
setEnvironment,
|
|
|
|
parseEnvironment,
|
2021-06-18 17:04:27 +00:00
|
|
|
} from '../ts/environment';
|
2018-01-30 00:57:49 +00:00
|
|
|
|
|
|
|
// In production mode, NODE_ENV cannot be customized by the user
|
2021-02-04 19:54:03 +00:00
|
|
|
if (app.isPackaged) {
|
|
|
|
setEnvironment(Environment.Production);
|
2018-01-30 00:57:49 +00:00
|
|
|
} else {
|
2021-02-04 19:54:03 +00:00
|
|
|
setEnvironment(parseEnvironment(process.env.NODE_ENV || 'development'));
|
2018-01-30 00:57:49 +00:00
|
|
|
}
|
2017-06-22 01:04:19 +00:00
|
|
|
|
|
|
|
// Set environment vars to configure node-config before requiring it
|
2021-02-04 19:54:03 +00:00
|
|
|
process.env.NODE_ENV = getEnvironment();
|
2021-06-18 17:04:27 +00:00
|
|
|
process.env.NODE_CONFIG_DIR = join(__dirname, '..', 'config');
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2021-02-04 19:54:03 +00:00
|
|
|
if (getEnvironment() === Environment.Production) {
|
2017-06-22 01:04:19 +00:00
|
|
|
// harden production config against the local env
|
|
|
|
process.env.NODE_CONFIG = '';
|
2022-06-13 21:39:35 +00:00
|
|
|
process.env.NODE_CONFIG_STRICT_MODE = '';
|
2017-06-22 01:04:19 +00:00
|
|
|
process.env.HOSTNAME = '';
|
|
|
|
process.env.NODE_APP_INSTANCE = '';
|
|
|
|
process.env.ALLOW_CONFIG_MUTATIONS = '';
|
|
|
|
process.env.SUPPRESS_NO_CONFIG_WARNING = '';
|
2019-04-16 00:12:57 +00:00
|
|
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '';
|
2019-12-17 20:25:57 +00:00
|
|
|
process.env.SIGNAL_ENABLE_HTTP = '';
|
2023-07-20 22:37:56 +00:00
|
|
|
process.env.SIGNAL_CI_CONFIG = '';
|
2017-06-22 01:04:19 +00:00
|
|
|
}
|
|
|
|
|
2018-01-13 00:14:45 +00:00
|
|
|
// We load config after we've made our modifications to NODE_ENV
|
2022-02-11 21:38:52 +00:00
|
|
|
// Note: we use `require()` because esbuild moves the imports to the top of
|
|
|
|
// the module regardless of their actual placement in the file.
|
|
|
|
// See: https://github.com/evanw/esbuild/issues/2011
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
|
|
const config: IConfig = require('config');
|
2017-06-22 01:04:19 +00:00
|
|
|
|
2024-03-12 16:35:52 +00:00
|
|
|
if (getEnvironment() !== Environment.Production) {
|
|
|
|
config.util.getConfigSources().forEach(source => {
|
|
|
|
console.log(`config: Using config source ${basename(source.name)}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-22 01:04:19 +00:00
|
|
|
// Log resulting env vars in use by config
|
|
|
|
[
|
|
|
|
'NODE_ENV',
|
|
|
|
'NODE_CONFIG_DIR',
|
|
|
|
'NODE_CONFIG',
|
|
|
|
'ALLOW_CONFIG_MUTATIONS',
|
|
|
|
'HOSTNAME',
|
|
|
|
'NODE_APP_INSTANCE',
|
2018-01-08 21:19:25 +00:00
|
|
|
'SUPPRESS_NO_CONFIG_WARNING',
|
2019-12-17 20:25:57 +00:00
|
|
|
'SIGNAL_ENABLE_HTTP',
|
2018-05-02 01:54:43 +00:00
|
|
|
].forEach(s => {
|
2018-01-08 21:19:25 +00:00
|
|
|
console.log(`${s} ${config.util.getEnv(s)}`);
|
2017-06-22 01:04:19 +00:00
|
|
|
});
|
|
|
|
|
2021-06-18 17:04:27 +00:00
|
|
|
export default config;
|
2021-10-01 18:49:59 +00:00
|
|
|
export type { IConfig as ConfigType };
|