UNPKG

3.45 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as http from "http";
3import * as https from "https";
4import ConfigurationBase from "./ConfigurationBase";
5import ICleaner from "./ICleaner";
6import IRequestListenerFactory from "./IRequestListenerFactory";
7export declare type RequestListener = (request: http.IncomingMessage, response: http.ServerResponse) => void;
8export declare enum ServerStatus {
9 Closed = "Closed",
10 Starting = "Starting",
11 Running = "Running",
12 Closing = "Closing"
13}
14/**
15 * Abstract Server class for Azurite HTTP or HTTPS Servers.
16 *
17 * @export
18 * @abstract
19 * @class Server
20 */
21export default abstract class ServerBase implements ICleaner {
22 readonly host: string;
23 readonly port: number;
24 readonly httpServer: http.Server | https.Server;
25 readonly config: ConfigurationBase;
26 protected status: ServerStatus;
27 /**
28 * Creates an instance of HTTP or HTTPS server.
29 *
30 * @param {string} host Server host,for example, "127.0.0.1"
31 * @param {number} port Server port, for example, 10000
32 * @param {http.Server | https.Server} httpServer A HTTP or HTTPS server instance without request listener bound
33 * @param {IRequestListenerFactory} requestListenerFactory A request listener factory
34 * @memberof ServerBase
35 */
36 constructor(host: string, port: number, httpServer: http.Server | https.Server, requestListenerFactory: IRequestListenerFactory, config: ConfigurationBase);
37 /**
38 * Get HTTP server listening address and port string.
39 * Note this may be different from host and port parameters values, because
40 * when port is 0, system will select a rand port number for listening.
41 * This method will return the port and address being used.
42 *
43 * @returns {string}
44 * @memberof ServerBase
45 */
46 getHttpServerAddress(): string;
47 getStatus(): ServerStatus;
48 /**
49 * Initialize and start the server to server incoming HTTP requests.
50 * beforeStart() and afterStart() will be executed before and after start().
51 *
52 * @abstract
53 * @returns {Promise<void>}
54 * @memberof Server
55 */
56 start(): Promise<void>;
57 /**
58 * Dispose HTTP server and clean up other resources.
59 *
60 * beforeClose() and afterClose() will be executed before and after close().
61 *
62 * We name this method as close instead of dispose, because in practices, usually we cannot re-open the resources
63 * disposed, but can re-open the resources closed.
64 *
65 * @abstract
66 * @returns {Promise<void>}
67 * @memberof Server
68 */
69 close(): Promise<void>;
70 clean(): Promise<void>;
71 /**
72 * Async task before server starts.
73 *
74 * @protected
75 * @abstract
76 * @returns {Promise<void>}
77 * @memberof Server
78 */
79 protected beforeStart(): Promise<void>;
80 /**
81 * Async task after server starts.
82 *
83 * @protected
84 * @abstract
85 * @returns {Promise<void>}
86 * @memberof Server
87 */
88 protected afterStart(): Promise<void>;
89 /**
90 * Async task before server closes.
91 *
92 * @protected
93 * @abstract
94 * @returns {Promise<void>}
95 * @memberof Server
96 */
97 protected beforeClose(): Promise<void>;
98 /**
99 * Async task after server closes.
100 *
101 * @protected
102 * @abstract
103 * @returns {Promise<void>}
104 * @memberof Server
105 */
106 protected afterClose(): Promise<void>;
107}
108//# sourceMappingURL=ServerBase.d.ts.map
\No newline at end of file