Skip to content

Commit c6df9e8

Browse files
committed
refactor: add support for built-in server options and rename functions
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 7748b7c commit c6df9e8

File tree

8 files changed

+174
-137
lines changed

8 files changed

+174
-137
lines changed

lib/node_modules/@stdlib/net/http-server/README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ limitations under the License.
2020

2121
# HTTP Server
2222

23-
> [HTTP][http] server.
23+
> [HTTP][nodejs-http] server.
2424
2525
<section class="usage">
2626

2727
## Usage
2828

2929
```javascript
30-
var httpServer = require( '@stdlib/net/http-server' );
30+
var httpServerFactory = require( '@stdlib/net/http-server' );
3131
```
3232

33-
#### httpServer( \[options,] \[ requestListener] )
33+
#### httpServerFactory( \[options,] \[ requestListener] )
3434

35-
Returns a function to create an [HTTP][http] server.
35+
Returns a function to create an [HTTP][nodejs-http] server.
3636

3737
```javascript
38-
var createServer = httpServer();
38+
var httpServer = httpServerFactory();
3939
```
4040

41+
The function supports the following parameters:
42+
43+
- **options**: options.
44+
- **requestListener**: callback to invoke upon receiving an HTTP request.
45+
4146
To bind a request callback to a server, provide a `requestListener`.
4247

4348
```javascript
@@ -46,25 +51,25 @@ function requestListener( request, response ) {
4651
response.end( 'OK' );
4752
}
4853

49-
var createServer = httpServer( requestListener );
54+
var httpServer = httpServerFactory( requestListener );
5055
```
5156

52-
The function accepts the following `options`:
57+
The function accepts the following options:
5358

5459
- **port**: server port. Default: `0` (i.e., randomly assigned).
5560
- **maxport**: max server port when port hunting. Default: `maxport=port`.
5661
- **hostname**: server hostname.
5762
- **address**: server address. Default: `127.0.0.1`.
5863

59-
To specify server options, provide an `options` object.
64+
To specify server options, provide an options object.
6065

6166
```javascript
6267
var opts = {
6368
'port': 7331,
6469
'address': '0.0.0.0'
6570
};
6671

67-
var createServer = httpServer( opts );
72+
var httpServer = httpServerFactory( opts );
6873
```
6974

7075
To specify a range of permissible ports, set the `maxport` option.
@@ -74,14 +79,14 @@ var opts = {
7479
'maxport': 9999
7580
};
7681

77-
var createServer = httpServer( opts );
82+
var httpServer = httpServerFactory( opts );
7883
```
7984

8085
When provided a `maxport` option, a created server will search for the first available `port` on which to listen, starting from `port`.
8186

82-
#### createServer( done )
87+
#### httpServer( \[options,] done )
8388

84-
Creates an [HTTP][http] server.
89+
Creates an [HTTP][nodejs-http] server.
8590

8691
```javascript
8792
function done( error, server ) {
@@ -92,11 +97,16 @@ function done( error, server ) {
9297
server.close();
9398
}
9499

95-
var createServer = httpServer();
100+
var httpServer = httpServerFactory();
96101

97-
createServer( done );
102+
httpServer( done );
98103
```
99104

105+
The function supports the following parameters:
106+
107+
- **options**: server options which are passed directly to [`http.createServer`][nodejs-http-create-server]. Which options are supported depends on the Node.js version. Older Node.js versions (e.g., <= v8.12.0) do not support an options object, and, for those versions, a provided options object is ignored.
108+
- **done**: callback to invoke once a server is listening and ready to handle requests.
109+
100110
</section>
101111

102112
<!-- /.usage -->
@@ -122,7 +132,7 @@ createServer( done );
122132
```javascript
123133
var proc = require( 'process' );
124134
var http = require( 'http' );
125-
var httpServer = require( '@stdlib/net/http-server' );
135+
var httpServerFactory = require( '@stdlib/net/http-server' );
126136

127137
function done( error, server ) {
128138
if ( error ) {
@@ -149,10 +159,10 @@ var opts = {
149159
};
150160

151161
// Create a function for creating an HTTP server...
152-
var createServer = httpServer( opts, onRequest );
162+
var httpServer = httpServerFactory( opts, onRequest );
153163

154164
// Create a server:
155-
createServer( done );
165+
httpServer( done );
156166
```
157167

158168
</section>
@@ -171,7 +181,9 @@ createServer( done );
171181

172182
<section class="links">
173183

174-
[http]: https://nodejs.org/api/http.html
184+
[nodejs-http]: https://nodejs.org/api/http.html
185+
186+
[nodejs-http-create-server]: https://nodejs.org/api/http.html#httpcreateserveroptions-requestlistener
175187

176188
</section>
177189

lib/node_modules/@stdlib/net/http-server/docs/repl.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,37 @@
2424

2525
Returns
2626
-------
27-
createServer: Function
27+
httpServer: Function
2828
Function to create an HTTP server.
2929

3030
Examples
3131
--------
3232
// Basic usage:
33-
> var createServer = {{alias}}()
33+
> var httpServer = {{alias}}()
3434
<Function>
3535

3636
// Provide a request callback:
3737
> function onRequest( request, response ) {
3838
... console.log( request.url );
3939
... response.end( 'OK' );
4040
... };
41-
> createServer = {{alias}}( onRequest )
41+
> httpServer = {{alias}}( onRequest )
4242
<Function>
4343

4444
// Specify a specific port:
4545
> var opts = { 'port': 7331 };
46-
> createServer = {{alias}}( opts )
46+
> httpServer = {{alias}}( opts )
4747
<Function>
4848

4949

50-
createServer( done )
50+
httpServer( [options,] done )
5151
Creates an HTTP server.
5252

5353
Parameters
5454
----------
55+
options: Object (optional)
56+
Server options which are passed directly to `http.createServer`.
57+
5558
done: Function
5659
Callback to invoke after creating a server.
5760

@@ -64,8 +67,8 @@ createServer( done )
6467
... console.log( 'Success!' );
6568
... server.close();
6669
... };
67-
> var createServer = {{alias}}();
68-
> createServer( done );
70+
> var httpServer = {{alias}}();
71+
> httpServer( done );
6972

7073
See Also
7174
--------

lib/node_modules/@stdlib/net/http-server/docs/types/index.d.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ type Callback = Nullary | Unary | Binary;
104104
*
105105
* @param done - callback to invoke after creating the server
106106
*/
107-
type createServer = ( done: Callback ) => void;
107+
type httpServer = ( done: Callback ) => void; // FIXME: need to allow for an `options` argument with support for built-in server options
108108

109109
/**
110110
* Returns a function which creates an HTTP server.
@@ -113,16 +113,16 @@ type createServer = ( done: Callback ) => void;
113113
* @returns function which creates an HTTP server
114114
*
115115
* @example
116-
* var createServer = httpServer();
116+
* var httpServer = factory();
117117
*
118118
* @example
119119
* function onRequest( request, response ) {
120120
* console.log( request.url );
121121
* response.end( 'OK' );
122122
* }
123-
* var createServer = httpServer( onRequest );
123+
* var httpServer = factory( onRequest );
124124
*/
125-
declare function httpServer( requestListener?: RequestListener ): createServer;
125+
declare function factory( requestListener?: RequestListener ): httpServer;
126126

127127
/**
128128
* Returns a function which creates an HTTP server.
@@ -141,7 +141,7 @@ declare function httpServer( requestListener?: RequestListener ): createServer;
141141
* 'port': 7331,
142142
* 'address': '0.0.0.0'
143143
* };
144-
* var createServer = httpServer( opts );
144+
* var httpServer = factory( opts );
145145
*
146146
* @example
147147
* var opts = {
@@ -152,11 +152,11 @@ declare function httpServer( requestListener?: RequestListener ): createServer;
152152
* console.log( request.url );
153153
* response.end( 'OK' );
154154
* }
155-
* var createServer = httpServer( opts, onRequest );
155+
* var httpServer = factory( opts, onRequest );
156156
*/
157-
declare function httpServer( options: Options, requestListener?: RequestListener ): createServer;
157+
declare function factory( options: Options, requestListener?: RequestListener ): httpServer;
158158

159159

160160
// EXPORTS //
161161

162-
export = httpServer;
162+
export = factory;

0 commit comments

Comments
 (0)