Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Server as HttpServer } from 'http';
import { Server as HttpsServer, ServerOptions as NodeHttpsServerOptions } from 'https';
import { Http2SecureServer, SecureServerOptions as NodeHttp2ServerOptions } from 'http2';

type IPAddress = string;
type FilePath = string;

type PEMPath = string;
type PEMData = string | Buffer;
type PEM = PEMPath | PEMData;
type PEMChain = PEM[];
type PEMs = PEM | PEMChain;
type CertificatePEMs = PEMs | PEMs[];

type CommonOptions = {
timeout?: number,
handler?: Function,
}

type ServerOptions = CommonOptions & {
port?: number,
host: IPAddress,
}

type HttpOptions = ServerOptions;

type TLSOptions = {
ciphers?: string,
honorCipherOrder?: boolean,
/**
* Required if ca, cert or key are FilePath
*/
root?: FilePath,
key?: PEM,
cert?: CertificatePEMs,
ca?: PEMs,
}

type SNIOptions = {
sni?: {
[hostname: string]: TLSOptions
}
}

type HttpsOptions = ServerOptions & TLSOptions & SNIOptions & NodeHttpsServerOptions;

type Http2Options = HttpsOptions & NodeHttp2ServerOptions;

type Options = {
http?: HttpOptions | Array<HttpOptions>,
https?: HttpsOptions | Array<HttpsOptions>,
http2?: Http2Options | Array<Http2Options>,
handler?: Function,
}

type Errors = {
message: string,
http?: Error | Error[],
https?: Error | Error[],
http2?: Error | Error[],
}

type Servers = {
http?: HttpServer | HttpServer[],
https?: HttpsServer | HttpsServer[],
http2?: Http2SecureServer | Http2SecureServer[],
}

type Callback = (error?: Errors, servers?: Servers) => void;

declare function createServers(options: Options, callback: Callback): void;

export = createServers;
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-servers",
"version": "3.2.0",
"version": "3.2.1",
"description": "Create an http AND/OR an https server and call the same request handler.",
"main": "index.js",
"scripts": {
Expand All @@ -27,6 +27,7 @@
"object-assign": "^4.1.0"
},
"devDependencies": {
"@types/node": "^16.3.3",
"evil-dns": "^0.2.0",
"sinon": "^5.0.7",
"tape": "~4.9.0"
Expand Down