1
1
import http = require( "http" ) ;
2
2
import type { Server as HTTPSServer } from "https" ;
3
- import type { Http2SecureServer } from "http2" ;
3
+ import type { Http2SecureServer , Http2Server } from "http2" ;
4
4
import { createReadStream } from "fs" ;
5
5
import { createDeflate , createGzip , createBrotliCompress } from "zlib" ;
6
6
import accepts = require( "accepts" ) ;
@@ -56,6 +56,12 @@ type ParentNspNameMatchFn = (
56
56
57
57
type AdapterConstructor = typeof Adapter | ( ( nsp : Namespace ) => Adapter ) ;
58
58
59
+ type TServerInstance =
60
+ | http . Server
61
+ | HTTPSServer
62
+ | Http2SecureServer
63
+ | Http2Server ;
64
+
59
65
interface ServerOptions extends EngineOptions , AttachOptions {
60
66
/**
61
67
* name of the path to capture
@@ -203,7 +209,7 @@ export class Server<
203
209
* @private
204
210
*/
205
211
_connectTimeout : number ;
206
- private httpServer : http . Server | HTTPSServer | Http2SecureServer ;
212
+ private httpServer : TServerInstance ;
207
213
private _corsMiddleware : (
208
214
req : http . IncomingMessage ,
209
215
res : http . ServerResponse ,
@@ -217,28 +223,13 @@ export class Server<
217
223
* @param [opts]
218
224
*/
219
225
constructor ( opts ?: Partial < ServerOptions > ) ;
226
+ constructor ( srv ?: TServerInstance | number , opts ?: Partial < ServerOptions > ) ;
220
227
constructor (
221
- srv ?: http . Server | HTTPSServer | Http2SecureServer | number ,
222
- opts ?: Partial < ServerOptions >
223
- ) ;
224
- constructor (
225
- srv :
226
- | undefined
227
- | Partial < ServerOptions >
228
- | http . Server
229
- | HTTPSServer
230
- | Http2SecureServer
231
- | number ,
228
+ srv : undefined | Partial < ServerOptions > | TServerInstance | number ,
232
229
opts ?: Partial < ServerOptions >
233
230
) ;
234
231
constructor (
235
- srv :
236
- | undefined
237
- | Partial < ServerOptions >
238
- | http . Server
239
- | HTTPSServer
240
- | Http2SecureServer
241
- | number ,
232
+ srv : undefined | Partial < ServerOptions > | TServerInstance | number ,
242
233
opts : Partial < ServerOptions > = { }
243
234
) {
244
235
super ( ) ;
@@ -271,9 +262,7 @@ export class Server<
271
262
opts . cleanupEmptyChildNamespaces = ! ! opts . cleanupEmptyChildNamespaces ;
272
263
this . sockets = this . of ( "/" ) ;
273
264
if ( srv || typeof srv == "number" )
274
- this . attach (
275
- srv as http . Server | HTTPSServer | Http2SecureServer | number
276
- ) ;
265
+ this . attach ( srv as TServerInstance | number ) ;
277
266
278
267
if ( this . opts . cors ) {
279
268
this . _corsMiddleware = corsMiddleware ( this . opts . cors ) ;
@@ -407,7 +396,7 @@ export class Server<
407
396
* @return self
408
397
*/
409
398
public listen (
410
- srv : http . Server | HTTPSServer | Http2SecureServer | number ,
399
+ srv : TServerInstance | number ,
411
400
opts : Partial < ServerOptions > = { }
412
401
) : this {
413
402
return this . attach ( srv , opts ) ;
@@ -421,7 +410,7 @@ export class Server<
421
410
* @return self
422
411
*/
423
412
public attach (
424
- srv : http . Server | HTTPSServer | Http2SecureServer | number ,
413
+ srv : TServerInstance | number ,
425
414
opts : Partial < ServerOptions > = { }
426
415
) : this {
427
416
if ( "function" == typeof srv ) {
@@ -527,7 +516,7 @@ export class Server<
527
516
* @private
528
517
*/
529
518
private initEngine (
530
- srv : http . Server | HTTPSServer | Http2SecureServer ,
519
+ srv : TServerInstance ,
531
520
opts : EngineOptions & AttachOptions
532
521
) : void {
533
522
// initialize engine
@@ -550,9 +539,7 @@ export class Server<
550
539
* @param srv http server
551
540
* @private
552
541
*/
553
- private attachServe (
554
- srv : http . Server | HTTPSServer | Http2SecureServer
555
- ) : void {
542
+ private attachServe ( srv : TServerInstance ) : void {
556
543
debug ( "attaching client serving req handler" ) ;
557
544
558
545
const evs = srv . listeners ( "request" ) . slice ( 0 ) ;
0 commit comments