signal-desktop/app/config.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2017-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { join } from 'path';
import { app } from 'electron';
2021-10-01 18:49:59 +00:00
import type { IConfig } from 'config';
import {
Environment,
getEnvironment,
setEnvironment,
parseEnvironment,
} from '../ts/environment';
// In production mode, NODE_ENV cannot be customized by the user
if (app.isPackaged) {
setEnvironment(Environment.Production);
} else {
setEnvironment(parseEnvironment(process.env.NODE_ENV || 'development'));
}
// Set environment vars to configure node-config before requiring it
process.env.NODE_ENV = getEnvironment();
process.env.NODE_CONFIG_DIR = join(__dirname, '..', 'config');
if (getEnvironment() === Environment.Production) {
// harden production config against the local env
process.env.NODE_CONFIG = '';
process.env.NODE_CONFIG_STRICT_MODE = '';
process.env.HOSTNAME = '';
process.env.NODE_APP_INSTANCE = '';
process.env.ALLOW_CONFIG_MUTATIONS = '';
process.env.SUPPRESS_NO_CONFIG_WARNING = '';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '';
2019-12-17 20:25:57 +00:00
process.env.SIGNAL_ENABLE_HTTP = '';
2022-07-05 16:44:53 +00:00
process.env.CUSTOM_TITLEBAR = '';
}
// 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');
// Log resulting env vars in use by config
[
'NODE_ENV',
'NODE_CONFIG_DIR',
'NODE_CONFIG',
'ALLOW_CONFIG_MUTATIONS',
'HOSTNAME',
'NODE_APP_INSTANCE',
'SUPPRESS_NO_CONFIG_WARNING',
2019-12-17 20:25:57 +00:00
'SIGNAL_ENABLE_HTTP',
].forEach(s => {
console.log(`${s} ${config.util.getEnv(s)}`);
});
export default config;
2021-10-01 18:49:59 +00:00
export type { IConfig as ConfigType };