1- import { ConnectionOptions } from 'tls'
2- import * as fs from 'fs'
3-
41function envString ( name : string , defaultValue ?: string ) : string {
52 const envValue = process . env [ name ]
63
@@ -25,42 +22,11 @@ export const Config = {
2522 trustProxy : envBool ( 'TRUST_PROXY' , false ) ,
2623 env : envString ( 'NODE_ENV' , 'development' ) ,
2724 cardServicePort : envInt ( 'CARD_SERVICE_PORT' , 3007 ) ,
28- cardServiceUrl : envString ( 'CARD_SERVICE_URL' , 'http://localhost:3007' ) ,
2925 cardPaymentTimeoutMS : envInt ( 'CARD_PAYMENT_TIMEOUT_MS' , 30000 ) ,
30- redisUrl : envString ( 'REDIS_URL' , 'redis://127.0.0.1:6379' ) ,
31- redisTls : parseRedisTlsConfig (
32- process . env . REDIS_TLS_CA_FILE_PATH ,
33- process . env . REDIS_TLS_KEY_FILE_PATH ,
34- process . env . REDIS_TLS_CERT_FILE_PATH
35- ) ,
3626 graphqlUrl : envString ( 'GRAPHQL_URL' ) ,
3727 tenantId : envString ( 'TENANT_ID' ) ,
3828 tenantSecret : envString ( 'TENANT_SECRET' ) ,
3929 tenantSignatureVersion : envString ( 'TENANT_SIGNATURE_VERSION' )
4030}
4131
42- function parseRedisTlsConfig (
43- caFile ?: string ,
44- keyFile ?: string ,
45- certFile ?: string
46- ) : ConnectionOptions | undefined {
47- const options : ConnectionOptions = { }
48-
49- // self-signed certs.
50- if ( caFile ) {
51- options . ca = fs . readFileSync ( caFile )
52- options . rejectUnauthorized = false
53- }
54-
55- if ( certFile ) {
56- options . cert = fs . readFileSync ( certFile )
57- }
58-
59- if ( keyFile ) {
60- options . key = fs . readFileSync ( keyFile )
61- }
62-
63- return Object . keys ( options ) . length > 0 ? options : undefined
64- }
65-
6632export type IAppConfig = typeof Config
0 commit comments