@@ -86,7 +86,7 @@ export class ApiServer {
86
86
private readonly log : Logger ;
87
87
private pluginRegistry : PluginRegistry | undefined ;
88
88
private readonly httpServerApi : Server | SecureServer ;
89
- private readonly httpServerCockpit : Server | SecureServer ;
89
+ private readonly httpServerCockpit ? : Server | SecureServer ;
90
90
private readonly wsApi : SocketIoServer ;
91
91
private readonly grpcServer : GrpcServer ;
92
92
private readonly expressApi : Application ;
@@ -129,15 +129,17 @@ export class ApiServer {
129
129
this . httpServerApi = createServer ( ) ;
130
130
}
131
131
132
- if ( this . options . httpServerCockpit ) {
133
- this . httpServerCockpit = this . options . httpServerCockpit ;
134
- } else if ( this . options . config . cockpitTlsEnabled ) {
135
- this . httpServerCockpit = createSecureServer ( {
136
- key : this . options . config . cockpitTlsKeyPem ,
137
- cert : this . options . config . cockpitTlsCertPem ,
138
- } ) ;
139
- } else {
140
- this . httpServerCockpit = createServer ( ) ;
132
+ if ( this . options . config . cockpitEnabled ) {
133
+ if ( this . options . httpServerCockpit ) {
134
+ this . httpServerCockpit = this . options . httpServerCockpit ;
135
+ } else if ( this . options . config . cockpitTlsEnabled ) {
136
+ this . httpServerCockpit = createSecureServer ( {
137
+ key : this . options . config . cockpitTlsKeyPem ,
138
+ cert : this . options . config . cockpitTlsCertPem ,
139
+ } ) ;
140
+ } else {
141
+ this . httpServerCockpit = createServer ( ) ;
142
+ }
141
143
}
142
144
143
145
this . grpcServer = this . options . grpcServer || new GrpcServer ( { } ) ;
@@ -194,7 +196,7 @@ export class ApiServer {
194
196
}
195
197
196
198
async start ( ) : Promise < {
197
- addressInfoCockpit : AddressInfo ;
199
+ addressInfoCockpit ? : AddressInfo ;
198
200
addressInfoApi : AddressInfo ;
199
201
addressInfoGrpc : AddressInfo ;
200
202
} > {
@@ -205,7 +207,10 @@ export class ApiServer {
205
207
206
208
try {
207
209
const { cockpitTlsEnabled, apiTlsEnabled } = this . options . config ;
208
- const addressInfoCockpit = await this . startCockpitFileServer ( ) ;
210
+ let addressInfoCockpit : AddressInfo | undefined ;
211
+ if ( this . options . config . cockpitEnabled ) {
212
+ addressInfoCockpit = await this . startCockpitFileServer ( ) ;
213
+ }
209
214
const addressInfoApi = await this . startApiServer ( ) ;
210
215
const addressInfoGrpc = await this . startGrpcServer ( ) ;
211
216
@@ -223,9 +228,9 @@ export class ApiServer {
223
228
this . log . info ( `Cactus API reachable ${ httpUrl } ` ) ;
224
229
}
225
230
226
- {
231
+ if ( this . options . config . cockpitEnabled ) {
227
232
const { cockpitHost : host } = this . options . config ;
228
- const { port } = addressInfoCockpit ;
233
+ const { port } = addressInfoCockpit as AddressInfo ;
229
234
const protocol = cockpitTlsEnabled ? "https:" : "http:" ;
230
235
const httpUrl = `${ protocol } //${ host } :${ port } ` ;
231
236
this . log . info ( `Cactus Cockpit reachable ${ httpUrl } ` ) ;
@@ -269,7 +274,7 @@ export class ApiServer {
269
274
return this . httpServerApi ;
270
275
}
271
276
272
- public getHttpServerCockpit ( ) : Server | SecureServer {
277
+ public getHttpServerCockpit ( ) : Server | SecureServer | undefined {
273
278
return this . httpServerCockpit ;
274
279
}
275
280
@@ -493,19 +498,19 @@ export class ApiServer {
493
498
const cockpitPort : number = this . options . config . cockpitPort ;
494
499
const cockpitHost : string = this . options . config . cockpitHost ;
495
500
496
- if ( ! this . httpServerCockpit . listening ) {
501
+ if ( ! this . httpServerCockpit ? .listening ) {
497
502
await new Promise ( ( resolve , reject ) => {
498
- this . httpServerCockpit . once ( "error" , reject ) ;
499
- this . httpServerCockpit . once ( "listening" , resolve ) ;
500
- this . httpServerCockpit . listen ( cockpitPort , cockpitHost ) ;
503
+ this . httpServerCockpit ? .once ( "error" , reject ) ;
504
+ this . httpServerCockpit ? .once ( "listening" , resolve ) ;
505
+ this . httpServerCockpit ? .listen ( cockpitPort , cockpitHost ) ;
501
506
} ) ;
502
507
}
503
- this . httpServerCockpit . on ( "request" , app ) ;
508
+ this . httpServerCockpit ? .on ( "request" , app ) ;
504
509
505
510
// the address() method returns a string for unix domain sockets and null
506
511
// if the server is not listening but we don't car about any of those cases
507
512
// so the casting here should be safe. Famous last words... I know.
508
- const addressInfo = this . httpServerCockpit . address ( ) as AddressInfo ;
513
+ const addressInfo = this . httpServerCockpit ? .address ( ) as AddressInfo ;
509
514
this . log . info ( `Cactus Cockpit net.AddressInfo` , addressInfo ) ;
510
515
511
516
return addressInfo ;
0 commit comments