@loopback/http-server 2.1.12 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/dist/http-server.d.ts +9 -3
- package/dist/http-server.js +32 -1
- package/dist/http-server.js.map +1 -1
- package/package.json +11 -9
- package/src/http-server.ts +62 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,45 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.3.0](https://github.com/strongloop/loopback-next/compare/@loopback/http-server@2.2.2...@loopback/http-server@2.3.0) (2020-10-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **http-server:** configure http.Server and Server properties ([42ad4b8](https://github.com/strongloop/loopback-next/commit/42ad4b887616879241337af1817fe30690641188))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [2.2.2](https://github.com/strongloop/loopback-next/compare/@loopback/http-server@2.2.1...@loopback/http-server@2.2.2) (2020-09-17)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @loopback/http-server
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## [2.2.1](https://github.com/strongloop/loopback-next/compare/@loopback/http-server@2.2.0...@loopback/http-server@2.2.1) (2020-09-15)
|
|
26
|
+
|
|
27
|
+
**Note:** Version bump only for package @loopback/http-server
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# [2.2.0](https://github.com/strongloop/loopback-next/compare/@loopback/http-server@2.1.12...@loopback/http-server@2.2.0) (2020-08-27)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* **http-server:** add debugging statements for http-server package ([ffde907](https://github.com/strongloop/loopback-next/commit/ffde907c188ca48163eb0ba1bb7b0e0ecb612367))
|
|
39
|
+
* **rest:** make sure rest options are passed to http-server ([e9af196](https://github.com/strongloop/loopback-next/commit/e9af1961dfe2aaae3c07e3100f6fe538797943e0))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
6
45
|
## [2.1.12](https://github.com/strongloop/loopback-next/compare/@loopback/http-server@2.1.11...@loopback/http-server@2.1.12) (2020-08-19)
|
|
7
46
|
|
|
8
47
|
**Note:** Version bump only for package @loopback/http-server
|
package/dist/http-server.d.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import http, { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import http, { IncomingMessage, Server, ServerResponse } from 'http';
|
|
3
3
|
import https from 'https';
|
|
4
4
|
import { AddressInfo, ListenOptions } from 'net';
|
|
5
5
|
/**
|
|
6
6
|
* Request listener function for http/https requests
|
|
7
7
|
*/
|
|
8
8
|
export declare type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
|
|
9
|
+
/**
|
|
10
|
+
* The following are for configuring properties which are directly set on
|
|
11
|
+
* https://nodejs.org/api/http.html#http_class_http_server and
|
|
12
|
+
* https://nodejs.org/api/net.html#net_class_net_server
|
|
13
|
+
*/
|
|
14
|
+
export declare type HttpServerProperties = Pick<Server, 'keepAliveTimeout' | 'headersTimeout' | 'maxConnections' | 'maxHeadersCount' | 'timeout'>;
|
|
9
15
|
/**
|
|
10
16
|
* Base options that are common to http and https servers
|
|
11
17
|
*/
|
|
12
|
-
export interface BaseHttpOptions extends ListenOptions {
|
|
18
|
+
export interface BaseHttpOptions extends ListenOptions, Partial<HttpServerProperties> {
|
|
13
19
|
/**
|
|
14
20
|
* The `gracePeriodForClose` property controls how to stop the server
|
|
15
21
|
* gracefully. Its value is the number of milliseconds to wait before
|
|
@@ -56,7 +62,7 @@ export declare class HttpServer {
|
|
|
56
62
|
private requestListener;
|
|
57
63
|
readonly server: http.Server | https.Server;
|
|
58
64
|
private _stoppable;
|
|
59
|
-
|
|
65
|
+
readonly serverOptions: HttpServerOptions;
|
|
60
66
|
/**
|
|
61
67
|
* @param requestListener
|
|
62
68
|
* @param serverOptions
|
package/dist/http-server.js
CHANGED
|
@@ -7,11 +7,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.HttpServer = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
10
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
10
11
|
const events_1 = require("events");
|
|
11
12
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
12
13
|
const https_1 = tslib_1.__importDefault(require("https"));
|
|
13
14
|
const os_1 = tslib_1.__importDefault(require("os"));
|
|
14
15
|
const stoppable_1 = tslib_1.__importDefault(require("stoppable"));
|
|
16
|
+
const debug = debug_1.default('loopback:http-server');
|
|
15
17
|
/**
|
|
16
18
|
* HTTP / HTTPS server used by LoopBack's RestServer
|
|
17
19
|
*/
|
|
@@ -23,9 +25,15 @@ class HttpServer {
|
|
|
23
25
|
constructor(requestListener, serverOptions) {
|
|
24
26
|
var _a;
|
|
25
27
|
this._listening = false;
|
|
28
|
+
debug('Http server options', serverOptions);
|
|
26
29
|
this.requestListener = requestListener;
|
|
27
|
-
this.serverOptions =
|
|
30
|
+
this.serverOptions = {
|
|
31
|
+
port: 0,
|
|
32
|
+
host: undefined,
|
|
33
|
+
...serverOptions,
|
|
34
|
+
};
|
|
28
35
|
if (this.serverOptions.path) {
|
|
36
|
+
debug('Http server with IPC path %s', this.serverOptions.path);
|
|
29
37
|
const ipcPath = this.serverOptions.path;
|
|
30
38
|
checkNamedPipe(ipcPath);
|
|
31
39
|
// Remove `port` so that `path` is honored
|
|
@@ -38,8 +46,26 @@ class HttpServer {
|
|
|
38
46
|
else {
|
|
39
47
|
this.server = http_1.default.createServer(this.requestListener);
|
|
40
48
|
}
|
|
49
|
+
// Apply server properties
|
|
50
|
+
const { keepAliveTimeout, headersTimeout, maxConnections, maxHeadersCount, timeout, } = this.serverOptions;
|
|
51
|
+
if (keepAliveTimeout) {
|
|
52
|
+
this.server.keepAliveTimeout = keepAliveTimeout;
|
|
53
|
+
}
|
|
54
|
+
if (headersTimeout) {
|
|
55
|
+
this.server.headersTimeout = headersTimeout;
|
|
56
|
+
}
|
|
57
|
+
if (maxConnections) {
|
|
58
|
+
this.server.maxConnections = maxConnections;
|
|
59
|
+
}
|
|
60
|
+
if (maxHeadersCount) {
|
|
61
|
+
this.server.maxHeadersCount = maxHeadersCount;
|
|
62
|
+
}
|
|
63
|
+
if (timeout) {
|
|
64
|
+
this.server.timeout = timeout;
|
|
65
|
+
}
|
|
41
66
|
// Set up graceful stop for http server
|
|
42
67
|
if (typeof this.serverOptions.gracePeriodForClose === 'number') {
|
|
68
|
+
debug('Http server gracePeriodForClose %d', this.serverOptions.gracePeriodForClose);
|
|
43
69
|
this._stoppable = stoppable_1.default(this.server, this.serverOptions.gracePeriodForClose);
|
|
44
70
|
}
|
|
45
71
|
}
|
|
@@ -47,12 +73,14 @@ class HttpServer {
|
|
|
47
73
|
* Starts the HTTP / HTTPS server
|
|
48
74
|
*/
|
|
49
75
|
async start() {
|
|
76
|
+
debug('Starting http server', this.serverOptions);
|
|
50
77
|
this.server.listen(this.serverOptions);
|
|
51
78
|
await events_1.once(this.server, 'listening');
|
|
52
79
|
this._listening = true;
|
|
53
80
|
const address = this.server.address();
|
|
54
81
|
assert_1.default(address != null);
|
|
55
82
|
this._address = address;
|
|
83
|
+
debug('Http server is listening on', this.url);
|
|
56
84
|
}
|
|
57
85
|
/**
|
|
58
86
|
* Stops the HTTP / HTTPS server
|
|
@@ -60,7 +88,9 @@ class HttpServer {
|
|
|
60
88
|
async stop() {
|
|
61
89
|
if (!this._listening)
|
|
62
90
|
return;
|
|
91
|
+
debug('Stopping http server');
|
|
63
92
|
if (this._stoppable != null) {
|
|
93
|
+
debug('Stopping http server with graceful close');
|
|
64
94
|
this._stoppable.stop();
|
|
65
95
|
}
|
|
66
96
|
else {
|
|
@@ -68,6 +98,7 @@ class HttpServer {
|
|
|
68
98
|
}
|
|
69
99
|
await events_1.once(this.server, 'close');
|
|
70
100
|
this._listening = false;
|
|
101
|
+
debug('Http server is stopped');
|
|
71
102
|
}
|
|
72
103
|
/**
|
|
73
104
|
* Protocol of the HTTP / HTTPS server
|
package/dist/http-server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,qCAAqC;AACrC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,4DAA4B;AAC5B,mCAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,qCAAqC;AACrC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,4DAA4B;AAC5B,0DAAiC;AACjC,mCAA4B;AAC5B,wDAAmE;AACnE,0DAA0B;AAE1B,oDAAoB;AACpB,kEAAkC;AAClC,MAAM,KAAK,GAAG,eAAY,CAAC,sBAAsB,CAAC,CAAC;AAuEnD;;GAEG;AACH,MAAa,UAAU;IASrB;;;OAGG;IACH,YACE,eAAgC,EAChC,aAAiC;;QAd3B,eAAU,GAAG,KAAK,CAAC;QAgBzB,KAAK,CAAC,qBAAqB,EAAE,aAAa,CAAC,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG;YACnB,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,SAAS;YACf,GAAG,aAAa;SACjB,CAAC;QACF,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE;YAC3B,KAA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IACzB,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;CACF;AAxKD,gCAwKC;AAED;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,OAAe;IACrC,wBAAwB;IACxB,IAAI,OAAO,EAAE,EAAE;QACb,MAAM,KAAK,GAAG,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;QACjD,gBAAM,CACJ,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EACtC,cAAc,OAAO,0BAA0B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACpE,CAAC;KACH;AACH,CAAC;AAED;;GAEG;AACH,SAAS,OAAO;IACd,OAAO,YAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/http-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A wrapper for creating HTTP/HTTPS servers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "
|
|
8
|
+
"node": "^10.16 || 12 || 14"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "lb-tsc",
|
|
@@ -21,15 +21,17 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"debug": "^4.2.0",
|
|
24
25
|
"stoppable": "^1.1.0",
|
|
25
|
-
"tslib": "^2.0.
|
|
26
|
+
"tslib": "^2.0.2"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@loopback/build": "^6.2.
|
|
29
|
-
"@loopback/core": "^2.
|
|
30
|
-
"@loopback/eslint-config": "^
|
|
31
|
-
"@loopback/testlab": "^3.2.
|
|
32
|
-
"@types/
|
|
29
|
+
"@loopback/build": "^6.2.5",
|
|
30
|
+
"@loopback/core": "^2.11.0",
|
|
31
|
+
"@loopback/eslint-config": "^10.0.1",
|
|
32
|
+
"@loopback/testlab": "^3.2.7",
|
|
33
|
+
"@types/debug": "^4.1.5",
|
|
34
|
+
"@types/node": "^10.17.35",
|
|
33
35
|
"@types/stoppable": "^1.1.0"
|
|
34
36
|
},
|
|
35
37
|
"files": [
|
|
@@ -43,5 +45,5 @@
|
|
|
43
45
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
44
46
|
"directory": "packages/http-server"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "390f2794d10eea3d969ae417963af815ce1bc417"
|
|
47
49
|
}
|
package/src/http-server.ts
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
6
|
import assert from 'assert';
|
|
7
|
+
import debugFactory from 'debug';
|
|
7
8
|
import {once} from 'events';
|
|
8
|
-
import http, {IncomingMessage, ServerResponse} from 'http';
|
|
9
|
+
import http, {IncomingMessage, Server, ServerResponse} from 'http';
|
|
9
10
|
import https from 'https';
|
|
10
11
|
import {AddressInfo, ListenOptions} from 'net';
|
|
11
12
|
import os from 'os';
|
|
12
13
|
import stoppable from 'stoppable';
|
|
14
|
+
const debug = debugFactory('loopback:http-server');
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Request listener function for http/https requests
|
|
@@ -19,10 +21,26 @@ export type RequestListener = (
|
|
|
19
21
|
res: ServerResponse,
|
|
20
22
|
) => void;
|
|
21
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The following are for configuring properties which are directly set on
|
|
26
|
+
* https://nodejs.org/api/http.html#http_class_http_server and
|
|
27
|
+
* https://nodejs.org/api/net.html#net_class_net_server
|
|
28
|
+
*/
|
|
29
|
+
export type HttpServerProperties = Pick<
|
|
30
|
+
Server,
|
|
31
|
+
| 'keepAliveTimeout'
|
|
32
|
+
| 'headersTimeout'
|
|
33
|
+
| 'maxConnections'
|
|
34
|
+
| 'maxHeadersCount'
|
|
35
|
+
| 'timeout'
|
|
36
|
+
>;
|
|
37
|
+
|
|
22
38
|
/**
|
|
23
39
|
* Base options that are common to http and https servers
|
|
24
40
|
*/
|
|
25
|
-
export interface BaseHttpOptions
|
|
41
|
+
export interface BaseHttpOptions
|
|
42
|
+
extends ListenOptions,
|
|
43
|
+
Partial<HttpServerProperties> {
|
|
26
44
|
/**
|
|
27
45
|
* The `gracePeriodForClose` property controls how to stop the server
|
|
28
46
|
* gracefully. Its value is the number of milliseconds to wait before
|
|
@@ -74,7 +92,7 @@ export class HttpServer {
|
|
|
74
92
|
private requestListener: RequestListener;
|
|
75
93
|
readonly server: http.Server | https.Server;
|
|
76
94
|
private _stoppable: stoppable.StoppableServer;
|
|
77
|
-
|
|
95
|
+
readonly serverOptions: HttpServerOptions;
|
|
78
96
|
|
|
79
97
|
/**
|
|
80
98
|
* @param requestListener
|
|
@@ -84,12 +102,15 @@ export class HttpServer {
|
|
|
84
102
|
requestListener: RequestListener,
|
|
85
103
|
serverOptions?: HttpServerOptions,
|
|
86
104
|
) {
|
|
105
|
+
debug('Http server options', serverOptions);
|
|
87
106
|
this.requestListener = requestListener;
|
|
88
|
-
this.serverOptions =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
this.serverOptions = {
|
|
108
|
+
port: 0,
|
|
109
|
+
host: undefined,
|
|
110
|
+
...serverOptions,
|
|
111
|
+
};
|
|
92
112
|
if (this.serverOptions.path) {
|
|
113
|
+
debug('Http server with IPC path %s', this.serverOptions.path);
|
|
93
114
|
const ipcPath = this.serverOptions.path;
|
|
94
115
|
checkNamedPipe(ipcPath);
|
|
95
116
|
// Remove `port` so that `path` is honored
|
|
@@ -104,8 +125,37 @@ export class HttpServer {
|
|
|
104
125
|
} else {
|
|
105
126
|
this.server = http.createServer(this.requestListener);
|
|
106
127
|
}
|
|
128
|
+
|
|
129
|
+
// Apply server properties
|
|
130
|
+
const {
|
|
131
|
+
keepAliveTimeout,
|
|
132
|
+
headersTimeout,
|
|
133
|
+
maxConnections,
|
|
134
|
+
maxHeadersCount,
|
|
135
|
+
timeout,
|
|
136
|
+
} = this.serverOptions;
|
|
137
|
+
if (keepAliveTimeout) {
|
|
138
|
+
this.server.keepAliveTimeout = keepAliveTimeout;
|
|
139
|
+
}
|
|
140
|
+
if (headersTimeout) {
|
|
141
|
+
this.server.headersTimeout = headersTimeout;
|
|
142
|
+
}
|
|
143
|
+
if (maxConnections) {
|
|
144
|
+
this.server.maxConnections = maxConnections;
|
|
145
|
+
}
|
|
146
|
+
if (maxHeadersCount) {
|
|
147
|
+
this.server.maxHeadersCount = maxHeadersCount;
|
|
148
|
+
}
|
|
149
|
+
if (timeout) {
|
|
150
|
+
this.server.timeout = timeout;
|
|
151
|
+
}
|
|
152
|
+
|
|
107
153
|
// Set up graceful stop for http server
|
|
108
154
|
if (typeof this.serverOptions.gracePeriodForClose === 'number') {
|
|
155
|
+
debug(
|
|
156
|
+
'Http server gracePeriodForClose %d',
|
|
157
|
+
this.serverOptions.gracePeriodForClose,
|
|
158
|
+
);
|
|
109
159
|
this._stoppable = stoppable(
|
|
110
160
|
this.server,
|
|
111
161
|
this.serverOptions.gracePeriodForClose,
|
|
@@ -117,6 +167,7 @@ export class HttpServer {
|
|
|
117
167
|
* Starts the HTTP / HTTPS server
|
|
118
168
|
*/
|
|
119
169
|
public async start() {
|
|
170
|
+
debug('Starting http server', this.serverOptions);
|
|
120
171
|
this.server.listen(this.serverOptions);
|
|
121
172
|
await once(this.server, 'listening');
|
|
122
173
|
this._listening = true;
|
|
@@ -124,6 +175,7 @@ export class HttpServer {
|
|
|
124
175
|
const address = this.server.address();
|
|
125
176
|
assert(address != null);
|
|
126
177
|
this._address = address!;
|
|
178
|
+
debug('Http server is listening on', this.url);
|
|
127
179
|
}
|
|
128
180
|
|
|
129
181
|
/**
|
|
@@ -131,13 +183,16 @@ export class HttpServer {
|
|
|
131
183
|
*/
|
|
132
184
|
public async stop() {
|
|
133
185
|
if (!this._listening) return;
|
|
186
|
+
debug('Stopping http server');
|
|
134
187
|
if (this._stoppable != null) {
|
|
188
|
+
debug('Stopping http server with graceful close');
|
|
135
189
|
this._stoppable.stop();
|
|
136
190
|
} else {
|
|
137
191
|
this.server.close();
|
|
138
192
|
}
|
|
139
193
|
await once(this.server, 'close');
|
|
140
194
|
this._listening = false;
|
|
195
|
+
debug('Http server is stopped');
|
|
141
196
|
}
|
|
142
197
|
|
|
143
198
|
/**
|