22 * @prettier
33 */
44import express from 'express' ;
5- import debug from 'debug' ;
65import https from 'https' ;
76import http from 'http' ;
87import superagent from 'superagent' ;
@@ -28,22 +27,20 @@ import { ProxyAgent } from 'proxy-agent';
2827import { promiseWrapper } from './routes' ;
2928import pjson from '../package.json' ;
3029import { handleGenerateWalletOnPrem } from './masterBitgoExpress/generateWallet' ;
30+ import logger from './logger' ;
3131
32- const debugLogger = debug ( 'master-express:express' ) ;
3332const BITGOEXPRESS_USER_AGENT = `BitGoExpress/${ pjson . version } BitGoJS/${ version } ` ;
3433
3534/**
3635 * Create a startup function which will be run upon server initialization
3736 */
3837export function startup ( config : MasterExpressConfig , baseUri : string ) : ( ) => void {
3938 return function ( ) {
40- /* eslint-disable no-console */
41- console . log ( 'BitGo Master Express running' ) ;
42- console . log ( `Base URI: ${ baseUri } ` ) ;
43- console . log ( `Environment: ${ config . env } ` ) ;
44- console . log ( `SSL Enabled: ${ config . enableSSL } ` ) ;
45- console . log ( `Proxy Enabled: ${ config . enableProxy } ` ) ;
46- /* eslint-enable no-console */
39+ logger . info ( 'BitGo Master Express running' ) ;
40+ logger . info ( `Base URI: ${ baseUri } ` ) ;
41+ logger . info ( `Environment: ${ config . env } ` ) ;
42+ logger . info ( `SSL Enabled: ${ config . enableSSL } ` ) ;
43+ logger . info ( `Proxy Enabled: ${ config . enableProxy } ` ) ;
4744 } ;
4845}
4946
@@ -123,12 +120,12 @@ async function createHttpsServer(
123120 if ( sslKey && sslCert ) {
124121 key = sslKey ;
125122 cert = sslCert ;
126- console . log ( 'Using SSL key and cert from environment variables' ) ;
123+ logger . info ( 'Using SSL key and cert from environment variables' ) ;
127124 } else if ( keyPath && crtPath ) {
128125 const certificates = await readCertificates ( keyPath , crtPath ) ;
129126 key = certificates . key ;
130127 cert = certificates . cert ;
131- console . log ( `Using SSL key and cert from files: ${ keyPath } , ${ crtPath } ` ) ;
128+ logger . info ( `Using SSL key and cert from files: ${ keyPath } , ${ crtPath } ` ) ;
132129 } else {
133130 throw new Error ( 'Failed to get SSL key and certificate' ) ;
134131 }
@@ -165,16 +162,17 @@ function setupMasterExpressRoutes(app: express.Application): void {
165162 setupHealthCheckRoutes ( app , 'master express' ) ;
166163
167164 const cfg = config ( ) as MasterExpressConfig ;
168- console . log ( 'SSL Enabled:' , cfg . enableSSL ) ;
169- console . log ( 'Enclaved Express URL:' , cfg . enclavedExpressUrl ) ;
170- console . log ( 'Certificate exists:' , Boolean ( cfg . enclavedExpressSSLCert ) ) ;
171- console . log ( 'Certificate length:' , cfg . enclavedExpressSSLCert . length ) ;
172- console . log ( 'Certificate content:' , cfg . enclavedExpressSSLCert ) ;
165+ logger . debug ( 'SSL Configuration:' , {
166+ sslEnabled : cfg . enableSSL ,
167+ enclavedExpressUrl : cfg . enclavedExpressUrl ,
168+ hasCertificate : Boolean ( cfg . enclavedExpressSSLCert ) ,
169+ certificateLength : cfg . enclavedExpressSSLCert . length ,
170+ } ) ;
173171
174172 // Add enclaved express ping route
175173 app . post ( '/ping/enclavedExpress' , async ( req , res ) => {
176174 try {
177- console . log ( 'Pinging enclaved express' ) ;
175+ logger . debug ( 'Pinging enclaved express' ) ;
178176
179177 const response = await superagent
180178 . get ( `${ cfg . enclavedExpressUrl } /ping` )
@@ -192,7 +190,7 @@ function setupMasterExpressRoutes(app: express.Application): void {
192190 enclavedResponse : response . body ,
193191 } ) ;
194192 } catch ( error ) {
195- debugLogger ( 'Failed to ping enclaved express:' , error ) ;
193+ logger . error ( 'Failed to ping enclaved express:' , { error } ) ;
196194 res . status ( 500 ) . json ( {
197195 error : 'Failed to ping enclaved express' ,
198196 details : error instanceof Error ? error . message : String ( error ) ,
@@ -215,19 +213,19 @@ function setupMasterExpressRoutes(app: express.Application): void {
215213 } ) ;
216214 } ) ;
217215
218- debugLogger ( 'Master express routes configured' ) ;
216+ logger . debug ( 'Master express routes configured' ) ;
219217}
220218
221219/**
222220 * Create and configure the express application for master express mode
223221 */
224222export function app ( cfg : MasterExpressConfig ) : express . Application {
225- debugLogger ( 'master express app is initializing' ) ;
223+ logger . debug ( 'master express app is initializing' ) ;
226224
227225 const app = express ( ) ;
228226
229227 setupLogging ( app , cfg ) ;
230- debugLogger ( 'logging setup' ) ;
228+ logger . debug ( 'logging setup' ) ;
231229
232230 setupDebugNamespaces ( cfg . debugNamespace ) ;
233231 setupCommonMiddleware ( app , cfg ) ;
@@ -236,7 +234,7 @@ export function app(cfg: MasterExpressConfig): express.Application {
236234 setupMasterExpressRoutes ( app ) ;
237235
238236 // Add error handler
239- app . use ( createErrorHandler ( debugLogger ) ) ;
237+ app . use ( createErrorHandler ( ) ) ;
240238
241239 return app ;
242240}
0 commit comments