Skip to content

Commit

Permalink
fix(db): use process.env as the default value of command option (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheben404 committed Jul 31, 2024
1 parent 9347595 commit b19493a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions apps/core/src/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { readFileSync } from 'node:fs'
import path from 'node:path'
import { seconds } from '@nestjs/throttler'
import { program } from 'commander'
import { load as yamlLoad } from 'js-yaml'
import { machineIdSync } from 'node-machine-id'

import { seconds } from '@nestjs/throttler'
import { machineIdSync } from 'node-machine-id'
import { isDebugMode, isDev } from './global/env.global'
import { parseBooleanishValue } from './utils'
import type { AxiosRequestConfig } from 'axios'

const { PORT: ENV_PORT, ALLOWED_ORIGINS, MX_ENCRYPT_KEY } = process.env

const commander = program
.option('-p, --port <number>', 'server port')
.option('-p, --port <number>', 'server port', ENV_PORT)
.option('--demo', 'enable demo mode')
.option(
'--allowed_origins <string>',
'allowed origins, e.g. innei.ren,*.innei.ren',
ALLOWED_ORIGINS,
)
.option('-c, --config <path>', 'load yaml config from file')

Expand Down Expand Up @@ -55,7 +58,11 @@ const commander = program
)

// security
.option('--encrypt_key <string>', 'custom encrypt key, default is machine-id')
.option(
'--encrypt_key <string>',
'custom encrypt key, default is machine-id',
MX_ENCRYPT_KEY,
)
.option(
'--encrypt_enable',
'enable encrypt security field, please remember encrypt key.',
Expand Down Expand Up @@ -88,9 +95,7 @@ if (argv.config) {
Object.assign(argv, config)
}

const { PORT: ENV_PORT, MX_ENCRYPT_KEY } = process.env

export const PORT = argv.port || ENV_PORT || 2333
export const PORT = argv.port || 2333
export const API_VERSION = 2

export const DEMO_MODE = argv.demo || false
Expand Down Expand Up @@ -177,7 +182,7 @@ export const THROTTLE_OPTIONS = {
limit: argv.throttle_limit ?? 100,
}

const ENCRYPT_KEY = argv.encrypt_key || MX_ENCRYPT_KEY
const ENCRYPT_KEY = argv.encrypt_key
export const ENCRYPT = {
key: ENCRYPT_KEY || machineIdSync(),
enable: parseBooleanishValue(argv.encrypt_enable) ?? !!ENCRYPT_KEY,
Expand Down

0 comments on commit b19493a

Please sign in to comment.