Skip to content

Commit

Permalink
fix(typings): add HTTPS server to accepted types (#4351)
Browse files Browse the repository at this point in the history
  • Loading branch information
h110m authored and darrachequesne committed May 3, 2022
1 parent 8ecfcba commit 9b43c91
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import http = require("http");
import type { Server as HTTPSServer } from "https";
import { createReadStream } from "fs";
import { createDeflate, createGzip, createBrotliCompress } from "zlib";
import accepts = require("accepts");
Expand Down Expand Up @@ -131,7 +132,7 @@ export class Server<
* @private
*/
_connectTimeout: number;
private httpServer: http.Server;
private httpServer: http.Server | HTTPSServer;

/**
* Server constructor.
Expand All @@ -141,13 +142,26 @@ export class Server<
* @public
*/
constructor(opts?: Partial<ServerOptions>);
constructor(srv?: http.Server | number, opts?: Partial<ServerOptions>);
constructor(
srv: undefined | Partial<ServerOptions> | http.Server | number,
srv?: http.Server | HTTPSServer | number,
opts?: Partial<ServerOptions>
);
constructor(
srv: undefined | Partial<ServerOptions> | http.Server | number,
srv:
| undefined
| Partial<ServerOptions>
| http.Server
| HTTPSServer
| number,
opts?: Partial<ServerOptions>
);
constructor(
srv:
| undefined
| Partial<ServerOptions>
| http.Server
| HTTPSServer
| number,
opts: Partial<ServerOptions> = {}
) {
super();
Expand All @@ -167,7 +181,8 @@ export class Server<
this.adapter(opts.adapter || Adapter);
this.sockets = this.of("/");
this.opts = opts;
if (srv || typeof srv == "number") this.attach(srv as http.Server | number);
if (srv || typeof srv == "number")
this.attach(srv as http.Server | HTTPSServer | number);
}

/**
Expand Down Expand Up @@ -300,7 +315,7 @@ export class Server<
* @public
*/
public listen(
srv: http.Server | number,
srv: http.Server | HTTPSServer | number,
opts: Partial<ServerOptions> = {}
): this {
return this.attach(srv, opts);
Expand All @@ -315,7 +330,7 @@ export class Server<
* @public
*/
public attach(
srv: http.Server | number,
srv: http.Server | HTTPSServer | number,
opts: Partial<ServerOptions> = {}
): this {
if ("function" == typeof srv) {
Expand Down Expand Up @@ -421,7 +436,7 @@ export class Server<
* @private
*/
private initEngine(
srv: http.Server,
srv: http.Server | HTTPSServer,
opts: EngineOptions & AttachOptions
): void {
// initialize engine
Expand All @@ -444,7 +459,7 @@ export class Server<
* @param srv http server
* @private
*/
private attachServe(srv: http.Server): void {
private attachServe(srv: http.Server | HTTPSServer): void {
debug("attaching client serving req handler");

const evs = srv.listeners("request").slice(0);
Expand Down

0 comments on commit 9b43c91

Please sign in to comment.