Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support environment variable for config 🚀 #489

Merged
merged 8 commits into from
Jun 11, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 21 additions & 11 deletions config/config.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,35 @@ export const cnpmcoreConfig: CnpmcoreConfig = {
enableUnpkg: true,
};

function getUserHome():string {
return process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'] || '';
}

export default (appInfo: EggAppConfig) => {
const config = {} as PowerPartial<EggAppConfig>;

config.cnpmcore = cnpmcoreConfig;

// override config from framework / plugin
config.dataDir = join(appInfo.root, '.cnpmcore');
config.dataDir = process.env.CNPMCORE_DATA_DIR || join(appInfo.root, '.cnpmcore');

config.orm = {
client: 'mysql',
database: process.env.MYSQL_DATABASE || 'cnpmcore',
host: process.env.MYSQL_HOST || '127.0.0.1',
port: process.env.MYSQL_PORT || 3306,
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PASSWORD,
database: process.env.CNPMCORE_MYSQL_DATABASE || process.env.MYSQL_DATABASE || 'cnpmcore',
host: process.env.CNPMCORE_MYSQL_HOST || process.env.MYSQL_HOST || '127.0.0.1',
port: process.env.CNPMCORE_MYSQL_PORT || process.env.MYSQL_PORT || 3306,
user: process.env.CNPMCORE_MYSQL_USER || process.env.MYSQL_USER || 'root',
password: process.env.CNPMCORE_MYSQL_PASSWORD || process.env.MYSQL_PASSWORD,
charset: 'utf8mb4',
logger: {},
};

config.redis = {
client: {
port: 6379,
host: '127.0.0.1',
password: '',
db: 0,
port: Number(process.env.CNPMCORE_REDIS_PORT || 6379),
host: process.env.CNPMCORE_REDIS_HOST || '127.0.0.1',
password: process.env.CNPMCORE_REDIS_PASSWORD || '',
db: Number(process.env.CNPMCORE_REDIS_DB || 0),
},
};

Expand All @@ -98,7 +102,7 @@ export default (appInfo: EggAppConfig) => {

config.nfs = {
client: null,
dir: join(config.dataDir, 'nfs'),
dir: process.env.CNPMCORE_NFS_DIR || join(config.dataDir, 'nfs'),
};
/* c8 ignore next 17 */
// enable oss nfs store by env values
Expand All @@ -122,6 +126,12 @@ export default (appInfo: EggAppConfig) => {
config.logger = {
enablePerformanceTimer: true,
enableFastContextLogger: true,
dir: process.env.CNPMCORE_LOG_DIR || join(getUserHome(), 'log1'),
fengmk2 marked this conversation as resolved.
Show resolved Hide resolved
appLogName: process.env.CNPMCORE_APP_LOG_NAME || `${appInfo.name}-web.log`,
coreLogName: process.env.CNPMCORE_CORE_LOG_NAME || 'egg-web.log',
agentLogName: process.env.CNPMCORE_AGENT_LOG_NAME || 'egg-agent.log',
errorLogName: process.env.CNPMCORE_ERROR_LOG_NAME || 'common-error.log',
outputJSON: Boolean(process.env.CNPMCORE_LOG_JSON_OUTPUT || false),
};

config.logrotator = {
Expand Down