@hyperledger/cactus-common
Version:
Universal library used by both front end and back end components of Cactus. Aims to be a developer swiss army knife.
33 lines (32 loc) • 1.31 kB
TypeScript
import { AddressInfo } from "net";
import { Server } from "http";
import { Server as SecureServer } from "https";
export interface IListenOptions {
server: Server | SecureServer;
port: number;
hostname: string;
}
/**
* Utility class for handling common tasks for NodeJS HTTP/S server objects.
*/
export declare class Servers {
/**
* Returns with a promise that resolves when the server has been shut down. Rejects if anything goes wrong of if the
* parameters are invalid.
*
* @param server The server object that will be shut down.
*/
static shutdown(server: Server | SecureServer): Promise<void>;
static listen(options: IListenOptions): Promise<AddressInfo>;
/**
* Start an HTTP server on the preferred port provided in the parameter if
* possible, bind to a random (0) port otherwise.
*
* @param preferredPort The TCP port the caller would **prefer** to use if
* possible. If the preferred port is taken, it will bind the server to port
* zero instead which means that the operating system will randomly choose an
* available port and use that.
*/
static startOnPreferredPort(preferredPort?: number, host?: string): Promise<Server>;
static startOnPort(port: number, host?: string): Promise<Server>;
}