@@ -88,10 +88,12 @@ export interface HttpStringFileResponse extends HttpResponse {
88
88
}
89
89
90
90
export interface HttpServerOptions {
91
+ readonly auth ?: AuthType
91
92
readonly basePath ?: string
92
93
readonly cert ?: string
93
94
readonly certKey ?: string
94
95
readonly host ?: string
96
+ readonly password ?: string
95
97
readonly port ?: number
96
98
readonly socket ?: string
97
99
}
@@ -108,7 +110,7 @@ interface ProviderRoute {
108
110
export interface HttpProviderOptions {
109
111
readonly base : string
110
112
readonly auth : AuthType
111
- readonly password : string | false
113
+ readonly password ? : string
112
114
}
113
115
114
116
/**
@@ -320,6 +322,14 @@ export class Heart {
320
322
}
321
323
}
322
324
325
+ export interface HttpProvider0 < T > {
326
+ new ( options : HttpProviderOptions ) : T
327
+ }
328
+
329
+ export interface HttpProvider1 < A1 , T > {
330
+ new ( options : HttpProviderOptions , a1 : A1 ) : T
331
+ }
332
+
323
333
/**
324
334
* An HTTP server. Its main role is to route incoming HTTP requests to the
325
335
* appropriate provider for that endpoint then write out the response. It also
@@ -372,15 +382,32 @@ export class HttpServer {
372
382
/**
373
383
* Register a provider for a top-level endpoint.
374
384
*/
375
- public registerHttpProvider < T extends HttpProvider > ( endpoint : string , provider : T ) : void {
385
+ public registerHttpProvider < T extends HttpProvider > ( endpoint : string , provider : HttpProvider0 < T > ) : void
386
+ public registerHttpProvider < A1 , T extends HttpProvider > (
387
+ endpoint : string ,
388
+ provider : HttpProvider1 < A1 , T > ,
389
+ a1 : A1
390
+ ) : void
391
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
+ public registerHttpProvider ( endpoint : string , provider : any , a1 ?: any ) : void {
376
393
endpoint = endpoint . replace ( / ^ \/ + | \/ + $ / g, "" )
377
394
if ( this . providers . has ( `/${ endpoint } ` ) ) {
378
395
throw new Error ( `${ endpoint } is already registered` )
379
396
}
380
397
if ( / \/ / . test ( endpoint ) ) {
381
398
throw new Error ( `Only top-level endpoints are supported (got ${ endpoint } )` )
382
399
}
383
- this . providers . set ( `/${ endpoint } ` , provider )
400
+ this . providers . set (
401
+ `/${ endpoint } ` ,
402
+ new provider (
403
+ {
404
+ auth : this . options . auth || AuthType . None ,
405
+ base : endpoint ,
406
+ password : this . options . password ,
407
+ } ,
408
+ a1
409
+ )
410
+ )
384
411
}
385
412
386
413
/**
0 commit comments