mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-10 07:28:06 -05:00
fix(typings): allow to bind to a non-secure Http2Server (#4853)
This commit is contained in:
45
lib/index.ts
45
lib/index.ts
@@ -1,6 +1,6 @@
|
||||
import http = require("http");
|
||||
import type { Server as HTTPSServer } from "https";
|
||||
import type { Http2SecureServer } from "http2";
|
||||
import type { Http2SecureServer, Http2Server } from "http2";
|
||||
import { createReadStream } from "fs";
|
||||
import { createDeflate, createGzip, createBrotliCompress } from "zlib";
|
||||
import accepts = require("accepts");
|
||||
@@ -56,6 +56,12 @@ type ParentNspNameMatchFn = (
|
||||
|
||||
type AdapterConstructor = typeof Adapter | ((nsp: Namespace) => Adapter);
|
||||
|
||||
type TServerInstance =
|
||||
| http.Server
|
||||
| HTTPSServer
|
||||
| Http2SecureServer
|
||||
| Http2Server;
|
||||
|
||||
interface ServerOptions extends EngineOptions, AttachOptions {
|
||||
/**
|
||||
* name of the path to capture
|
||||
@@ -203,7 +209,7 @@ export class Server<
|
||||
* @private
|
||||
*/
|
||||
_connectTimeout: number;
|
||||
private httpServer: http.Server | HTTPSServer | Http2SecureServer;
|
||||
private httpServer: TServerInstance;
|
||||
private _corsMiddleware: (
|
||||
req: http.IncomingMessage,
|
||||
res: http.ServerResponse,
|
||||
@@ -217,28 +223,13 @@ export class Server<
|
||||
* @param [opts]
|
||||
*/
|
||||
constructor(opts?: Partial<ServerOptions>);
|
||||
constructor(srv?: TServerInstance | number, opts?: Partial<ServerOptions>);
|
||||
constructor(
|
||||
srv?: http.Server | HTTPSServer | Http2SecureServer | number,
|
||||
srv: undefined | Partial<ServerOptions> | TServerInstance | number,
|
||||
opts?: Partial<ServerOptions>
|
||||
);
|
||||
constructor(
|
||||
srv:
|
||||
| undefined
|
||||
| Partial<ServerOptions>
|
||||
| http.Server
|
||||
| HTTPSServer
|
||||
| Http2SecureServer
|
||||
| number,
|
||||
opts?: Partial<ServerOptions>
|
||||
);
|
||||
constructor(
|
||||
srv:
|
||||
| undefined
|
||||
| Partial<ServerOptions>
|
||||
| http.Server
|
||||
| HTTPSServer
|
||||
| Http2SecureServer
|
||||
| number,
|
||||
srv: undefined | Partial<ServerOptions> | TServerInstance | number,
|
||||
opts: Partial<ServerOptions> = {}
|
||||
) {
|
||||
super();
|
||||
@@ -271,9 +262,7 @@ export class Server<
|
||||
opts.cleanupEmptyChildNamespaces = !!opts.cleanupEmptyChildNamespaces;
|
||||
this.sockets = this.of("/");
|
||||
if (srv || typeof srv == "number")
|
||||
this.attach(
|
||||
srv as http.Server | HTTPSServer | Http2SecureServer | number
|
||||
);
|
||||
this.attach(srv as TServerInstance | number);
|
||||
|
||||
if (this.opts.cors) {
|
||||
this._corsMiddleware = corsMiddleware(this.opts.cors);
|
||||
@@ -407,7 +396,7 @@ export class Server<
|
||||
* @return self
|
||||
*/
|
||||
public listen(
|
||||
srv: http.Server | HTTPSServer | Http2SecureServer | number,
|
||||
srv: TServerInstance | number,
|
||||
opts: Partial<ServerOptions> = {}
|
||||
): this {
|
||||
return this.attach(srv, opts);
|
||||
@@ -421,7 +410,7 @@ export class Server<
|
||||
* @return self
|
||||
*/
|
||||
public attach(
|
||||
srv: http.Server | HTTPSServer | Http2SecureServer | number,
|
||||
srv: TServerInstance | number,
|
||||
opts: Partial<ServerOptions> = {}
|
||||
): this {
|
||||
if ("function" == typeof srv) {
|
||||
@@ -527,7 +516,7 @@ export class Server<
|
||||
* @private
|
||||
*/
|
||||
private initEngine(
|
||||
srv: http.Server | HTTPSServer | Http2SecureServer,
|
||||
srv: TServerInstance,
|
||||
opts: EngineOptions & AttachOptions
|
||||
): void {
|
||||
// initialize engine
|
||||
@@ -550,9 +539,7 @@ export class Server<
|
||||
* @param srv http server
|
||||
* @private
|
||||
*/
|
||||
private attachServe(
|
||||
srv: http.Server | HTTPSServer | Http2SecureServer
|
||||
): void {
|
||||
private attachServe(srv: TServerInstance): void {
|
||||
debug("attaching client serving req handler");
|
||||
|
||||
const evs = srv.listeners("request").slice(0);
|
||||
|
||||
Reference in New Issue
Block a user