Skip to content

Commit 4309b4d

Browse files
committed
Auto-generated commit
1 parent 0ec42aa commit 4309b4d

File tree

21 files changed

+2053
-17
lines changed

21 files changed

+2053
-17
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66

77
## Unreleased (2025-08-16)
88

9+
<section class="features">
10+
11+
### Features
12+
13+
- [`6c3f6fe`](https://github.com/stdlib-js/stdlib/commit/6c3f6fe6f732b28c68637aa2c651c451c740a8e1) - add `http2SecureServer` to namespace
14+
- [`fd25355`](https://github.com/stdlib-js/stdlib/commit/fd253551235716d6732acc99ca9dfe6363bd577d) - add `net/http2-secure-server`
15+
16+
</section>
17+
18+
<!-- /.features -->
19+
920
<section class="bug-fixes">
1021

1122
### Bug Fixes
@@ -22,6 +33,12 @@
2233

2334
<details>
2435

36+
- [`9f3732f`](https://github.com/stdlib-js/stdlib/commit/9f3732f2587d7e0f4ad16589ca5900b0cf20bbc0) - **docs:** fix examples _(by Athan Reines)_
37+
- [`1f08a8b`](https://github.com/stdlib-js/stdlib/commit/1f08a8b3c6f9c39c316380b1c059ddac187d004c) - **docs:** fix examples _(by Athan Reines)_
38+
- [`465d54a`](https://github.com/stdlib-js/stdlib/commit/465d54a5f86566d92668f524dadd08d6127f85d4) - **test:** fix option name _(by Athan Reines)_
39+
- [`4eb8f54`](https://github.com/stdlib-js/stdlib/commit/4eb8f54376072921b0c76058dd239341a205acbc) - **test:** fix option name _(by Athan Reines)_
40+
- [`6c3f6fe`](https://github.com/stdlib-js/stdlib/commit/6c3f6fe6f732b28c68637aa2c651c451c740a8e1) - **feat:** add `http2SecureServer` to namespace _(by Athan Reines)_
41+
- [`fd25355`](https://github.com/stdlib-js/stdlib/commit/fd253551235716d6732acc99ca9dfe6363bd577d) - **feat:** add `net/http2-secure-server` _(by Athan Reines)_
2542
- [`212b623`](https://github.com/stdlib-js/stdlib/commit/212b623d3f01f92a8bbf29b6e8f6e67fa879cb40) - **docs:** rename function alias _(by Athan Reines)_
2643
- [`1c9a2da`](https://github.com/stdlib-js/stdlib/commit/1c9a2dad4c7ff11aefab03110d9c0fa7ad94e969) - **docs:** update copy _(by Athan Reines)_
2744
- [`d02db19`](https://github.com/stdlib-js/stdlib/commit/d02db19483a002759417943f0a6c8521fdfe1a4c) - **docs:** update note _(by Athan Reines)_

http-server/docs/types/test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ function done( error: Error | null, server: any ) {
9090
httpServerFactory( { 'port': ( x: number ): number => x }, requestListener ); // $ExpectError
9191
}
9292

93-
// The compiler throws an error if the function is provided a `maxPort` option which is not a number...
93+
// The compiler throws an error if the function is provided a `maxport` option which is not a number...
9494
{
95-
httpServerFactory( { 'maxPort': 'abc' }, requestListener ); // $ExpectError
96-
httpServerFactory( { 'maxPort': true }, requestListener ); // $ExpectError
97-
httpServerFactory( { 'maxPort': false }, requestListener ); // $ExpectError
98-
httpServerFactory( { 'maxPort': null }, requestListener ); // $ExpectError
99-
httpServerFactory( { 'maxPort': [] }, requestListener ); // $ExpectError
100-
httpServerFactory( { 'maxPort': {} }, requestListener ); // $ExpectError
101-
httpServerFactory( { 'maxPort': ( x: number ): number => x }, requestListener ); // $ExpectError
95+
httpServerFactory( { 'maxport': 'abc' }, requestListener ); // $ExpectError
96+
httpServerFactory( { 'maxport': true }, requestListener ); // $ExpectError
97+
httpServerFactory( { 'maxport': false }, requestListener ); // $ExpectError
98+
httpServerFactory( { 'maxport': null }, requestListener ); // $ExpectError
99+
httpServerFactory( { 'maxport': [] }, requestListener ); // $ExpectError
100+
httpServerFactory( { 'maxport': {} }, requestListener ); // $ExpectError
101+
httpServerFactory( { 'maxport': ( x: number ): number => x }, requestListener ); // $ExpectError
102102
}
103103

104104
// The compiler throws an error if the function is provided a `hostname` option which is not a string...

http2-secure-server/README.md

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# HTTP/2 Server
22+
23+
> [HTTP/2][nodejs-http2] server.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var http2ServerFactory = require( '@stdlib/net/http2-secure-server' );
31+
```
32+
33+
#### http2ServerFactory( options\[, requestListener] )
34+
35+
Returns a function to create an [HTTP/2][nodejs-http2] server.
36+
37+
```javascript
38+
var resolve = require( 'path' ).resolve;
39+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
40+
41+
var opts = {
42+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
43+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
44+
};
45+
var http2Server = http2ServerFactory( opts );
46+
```
47+
48+
The function supports the following parameters:
49+
50+
- **options**: options.
51+
- **requestListener**: callback to invoke upon receiving an HTTP request (_optional_).
52+
53+
To bind a request callback to a server, provide a `requestListener`.
54+
55+
```javascript
56+
var resolve = require( 'path' ).resolve;
57+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
58+
59+
function requestListener( request, response ) {
60+
console.log( request.url );
61+
response.end( 'OK' );
62+
}
63+
64+
var opts = {
65+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
66+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
67+
};
68+
var http2Server = http2ServerFactory( opts, requestListener );
69+
```
70+
71+
In addition to the options supported by [`http2.createSecureServer`][nodejs-http2-create-secure-server], the function accepts the following options:
72+
73+
- **port**: server port. Default: `0` (i.e., randomly assigned).
74+
- **maxport**: max server port when port hunting. Default: `maxport=port`.
75+
- **hostname**: server hostname.
76+
- **address**: server address. Default: `127.0.0.1`.
77+
78+
To specify server options, provide an options object.
79+
80+
```javascript
81+
var resolve = require( 'path' ).resolve;
82+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
83+
84+
var opts = {
85+
'port': 7331,
86+
'address': '0.0.0.0',
87+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
88+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
89+
};
90+
91+
var http2Server = http2ServerFactory( opts );
92+
```
93+
94+
To specify a range of permissible ports, set the `maxport` option.
95+
96+
```javascript
97+
var resolve = require( 'path' ).resolve;
98+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
99+
100+
var opts = {
101+
'maxport': 9999,
102+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
103+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
104+
};
105+
106+
var http2Server = http2ServerFactory( opts );
107+
```
108+
109+
When provided a `maxport` option, a created server will search for the first available `port` on which to listen, starting from `port`.
110+
111+
#### http2Server( done )
112+
113+
Creates an [HTTP/2][nodejs-http2] server.
114+
115+
```javascript
116+
var resolve = require( 'path' ).resolve;
117+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
118+
119+
function done( error, server ) {
120+
if ( error ) {
121+
throw error;
122+
}
123+
console.log( 'Success!' );
124+
server.close();
125+
}
126+
127+
var opts = {
128+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
129+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
130+
};
131+
var http2Server = http2ServerFactory( opts );
132+
133+
http2Server( done );
134+
```
135+
136+
The function supports the following parameters:
137+
138+
- **done**: callback to invoke once a server is listening and ready to handle requests.
139+
140+
</section>
141+
142+
<!-- /.usage -->
143+
144+
<section class="notes">
145+
146+
## Notes
147+
148+
- Which server options are supported depends on the Node.js version.
149+
- Port hunting can be useful in a microservice deployment. When a `port` is randomly assigned (`options.port=0`), if a server fails and is restarted, the server is unlikely to bind to its previous `port`. By allowing a constrained search, assuming no lower `ports` within a specified range have freed up in the meantime, the likelihood of listening on the same `port` is increased. A server can typically restart and bind to the same `port` faster than binding to a new `port` and re-registering with a microservice registry, thus minimizing possible service interruption and downtime.
150+
151+
</section>
152+
153+
<!-- /.notes -->
154+
155+
<section class="examples">
156+
157+
## Examples
158+
159+
<!-- eslint-disable node/no-process-exit, node/no-unsupported-features/node-builtins -->
160+
161+
<!-- eslint no-undef: "error" -->
162+
163+
```javascript
164+
var proc = require( 'process' );
165+
var http2 = require( 'http2' );
166+
var resolve = require( 'path' ).resolve;
167+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
168+
var http2ServerFactory = require( '@stdlib/net/http2-secure-server' );
169+
170+
function done( error ) {
171+
var client;
172+
var req;
173+
if ( error ) {
174+
throw error;
175+
}
176+
client = http2.connect( 'https://localhost:7331', {
177+
'ca': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) )
178+
});
179+
req = client.request({
180+
':path': '/beep/boop'
181+
});
182+
req.on( 'response', onResponse );
183+
req.end();
184+
185+
function onResponse() {
186+
console.log( 'Success!' );
187+
client.close();
188+
proc.exit( 0 );
189+
}
190+
}
191+
192+
function onRequest( request, response ) {
193+
console.log( request.url );
194+
response.end( 'OK' );
195+
}
196+
197+
// Specify server options...
198+
var opts = {
199+
'port': 7331,
200+
'maxport': 9999,
201+
'hostname': 'localhost',
202+
'allowHTTP1': true,
203+
'cert': readFileSync( resolve( __dirname, 'examples', 'localhost-cert.pem' ) ),
204+
'key': readFileSync( resolve( __dirname, 'examples', 'localhost-privkey.pem' ) )
205+
};
206+
207+
// Create a function for creating an HTTP/2 server...
208+
var http2Server = http2ServerFactory( opts, onRequest );
209+
210+
// Create a server:
211+
http2Server( done );
212+
```
213+
214+
</section>
215+
216+
<!-- /.examples -->
217+
218+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
219+
220+
<section class="related">
221+
222+
</section>
223+
224+
<!-- /.related -->
225+
226+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
227+
228+
<section class="links">
229+
230+
[nodejs-http2]: https://nodejs.org/api/http2.html
231+
232+
[nodejs-http2-create-secure-server]: https://nodejs.org/api/http2.html#http2createsecureserveroptions-onrequesthandler
233+
234+
</section>
235+
236+
<!-- /.links -->

http2-secure-server/docs/repl.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
{{alias}}( options, [requestListener] )
3+
Returns a function to create an HTTP/2 server.
4+
5+
In addition to options documented below, the function supports any options
6+
supported by `http2.createSecureServer`. Which server options are supported
7+
depends on the Node.js version.
8+
9+
Either the `pfx` option or the `key`/`cert` options must be provided.
10+
11+
Parameters
12+
----------
13+
options: Object
14+
Options.
15+
16+
options.pfx: string|Buffer|Array<string|Buffer|Object> (optional)
17+
PFX or PKCS12 encode private key and certificate chain.
18+
19+
options.cert: string|Buffer|Array<string|Buffer> (optional)
20+
Cert chains in PEM format.
21+
22+
options.key: string|Buffer|Array<string|Buffer|Object> (optional)
23+
Private keys in PEM format.
24+
25+
options.port: integer (optional)
26+
Server port. Default: `0` (i.e., randomly assigned).
27+
28+
options.maxport: integer (optional)
29+
Max server port when port hunting. Default: `maxport = port`.
30+
31+
options.hostname: string (optional)
32+
Server hostname.
33+
34+
options.address: string (optional)
35+
Server address. Default: `'127.0.0.1'`.
36+
37+
requestListener: Function (optional)
38+
Request callback.
39+
40+
Returns
41+
-------
42+
http2Server: Function
43+
Function to create an HTTP/2 server.
44+
45+
Examples
46+
--------
47+
> function onRequest( request, response ) {
48+
... console.log( request.url );
49+
... response.end( 'OK' );
50+
... };
51+
> var opts = { 'port': 7331, 'cert': '...', 'key': '...' };
52+
> var boot = {{alias}}( opts, onRequest )
53+
<Function>
54+
55+
56+
boot( done )
57+
Creates an HTTP/2 server.
58+
59+
Parameters
60+
----------
61+
done: Function
62+
Callback to invoke after creating a server.
63+
64+
Examples
65+
--------
66+
> function done( error, server ) {
67+
... if ( error ) {
68+
... throw error;
69+
... }
70+
... console.log( 'Success!' );
71+
... server.close();
72+
... };
73+
> var opts = { 'cert': '...', 'key': '...' };
74+
> var boot = {{alias}}();
75+
> boot( done );
76+
77+
See Also
78+
--------
79+

0 commit comments

Comments
 (0)