-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http-server): make http2 server creation extensible
- Loading branch information
1 parent
86bfcbc
commit b9cb3e0
Showing
8 changed files
with
352 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: @loopback/http-server | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export * from './types'; | ||
export * from './http-server'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import {AddressInfo} from 'net'; | ||
import * as http from 'http'; | ||
import * as https from 'https'; | ||
import {IncomingMessage, ServerResponse} from 'http'; | ||
|
||
// Copyright IBM Corp. 2018. All Rights Reserved. | ||
// Node module: @loopback/http-server | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
export type RequestListener = ( | ||
req: IncomingMessage, | ||
res: ServerResponse, | ||
) => void; | ||
|
||
/** | ||
* Basic HTTP server listener options | ||
* | ||
* @export | ||
* @interface ListenerOptions | ||
*/ | ||
export interface ListenerOptions { | ||
host?: string; | ||
port?: number; | ||
} | ||
|
||
/** | ||
* HTTP server options | ||
* | ||
* @export | ||
* @interface HttpOptions | ||
*/ | ||
export interface HttpOptions extends ListenerOptions { | ||
protocol?: 'http'; | ||
} | ||
|
||
/** | ||
* HTTPS server options | ||
* | ||
* @export | ||
* @interface HttpsOptions | ||
*/ | ||
export interface HttpsOptions extends ListenerOptions, https.ServerOptions { | ||
protocol: 'https'; | ||
} | ||
|
||
/** | ||
* HTTP/2 server options | ||
* | ||
* @export | ||
* @interface Http2Options | ||
*/ | ||
export interface Http2Options extends ListenerOptions { | ||
protocol: 'http2'; | ||
// Other options for a module like https://github.com/spdy-http2/node-spdy | ||
[name: string]: unknown; | ||
} | ||
|
||
/** | ||
* Possible server options | ||
* | ||
* @export | ||
* @type HttpServerOptions | ||
*/ | ||
export type HttpServerOptions = HttpOptions | HttpsOptions | Http2Options; | ||
|
||
/** | ||
* Supported protocols | ||
* | ||
* @export | ||
* @type HttpProtocol | ||
*/ | ||
export type HttpProtocol = 'http' | 'https' | 'http2'; | ||
|
||
/** | ||
* HTTP / HTTPS server used by LoopBack's RestServer | ||
* | ||
* @export | ||
* @class HttpServer | ||
*/ | ||
export interface HttpServer { | ||
readonly server: http.Server | https.Server; | ||
readonly protocol: HttpProtocol; | ||
readonly port: number; | ||
readonly host: string | undefined; | ||
readonly url: string; | ||
readonly listening: boolean; | ||
readonly address: AddressInfo | undefined; | ||
|
||
start(): Promise<void>; | ||
stop(): Promise<void>; | ||
} | ||
|
||
/** | ||
* A factory to create http servers | ||
*/ | ||
export interface HttpServerFactory { | ||
create( | ||
requestListener: RequestListener, | ||
serverOptions?: HttpServerOptions, | ||
): HttpServer; | ||
} |
Oops, something went wrong.