Skip to content

Commit f147418

Browse files
jpage-godaddyindexzero
authored andcommitted
Usage documentation (#17)
* Add full documentation for all available config options * Normalize heading levels
1 parent e09b4aa commit f147418

File tree

3 files changed

+465
-11
lines changed

3 files changed

+465
-11
lines changed

README.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,60 @@
1-
create-servers
2-
==============
1+
# create-servers
32

43
Create an http AND/OR an https server and call the same request handler.
54

6-
*NOTE on Security*
5+
## Usage
6+
7+
The `create-servers` module exports a function that takes a config object and
8+
a node-style callback. The config object must have at minimum an `http` or
9+
`https` property (or both). The following config properties are supported:
10+
11+
| Property | Description |
12+
|---------------------------|-------------|
13+
| `handler` | Request handler to be used for any server, unless overridden specifically with `http.handler` or `https.handler`. |
14+
| `timeout` | Socket timeout in milliseconds for any server, unless overridden with `http.timeout` or `https.timeout`. Defaults to the node default of 2 minutes. |
15+
| `http` | Optional. If present, an HTTP server is started. This can be an object or a number. If it's a number, it's used as the TCP port for an HTTP server. |
16+
| `http.port` | TCP port for the HTTP server. Defaults to `80`. |
17+
| `http.host` | The address the HTTP server is bound to. Defaults to `::` or `0.0.0.0`. |
18+
| `http.timeout` | Socket timeout in milliseconds for the server. If unspecified, the top-level `timeout` configuration is used. |
19+
| `http.handler` | Handler for HTTP requests. If you want to share a handler with all servers, use a top-level `handler` config property instead. |
20+
| `https` | Optional object. If present, an HTTPS server is started. |
21+
| `https.port` | TCP port for the HTTPS server. Defaults to `443`. |
22+
| `https.host` | The address the HTTPS server is bound to. Defaults to `::` or `0.0.0.0`. |
23+
| `https.timeout` | Socket timeout in milliseconds for the server. If unspecified, the top-level `timeout` configuration is used. |
24+
| `https.ciphers` | Defaults to a [default cipher suite](#note-on-security). To customize, either supply a colon-separated string or array of strings for the ciphers you want the server to support. |
25+
| `https.honorCipherOrder` | If true, prefer the server's specified cipher order instead of the client's. Defaults to `false`. |
26+
| `https.root` | Root directory for certificate/key files. See [Certificate normalization](#certificate-normalization) for more details. |
27+
| `https.key` | PEM/file path for the server's private key. See [Certificate normalization](#certificate-normalization) for more details. |
28+
| `https.cert` | PEM/file path(s) for the server's certificate. See [Certificate normalization](#certificate-normalization) for more details. |
29+
| `https.ca` | Cert or array of certs specifying trusted authorities for peer certificates. Only required if your server accepts client certificate connections signed by authorities that are not trusted by default. See [Certificate normalization](#certificate-normalization) for more details. |
30+
| `https.handler` | Handler for HTTPS requests. If you want to share a handler with all servers, use a top-level `handler` config property instead. |
31+
| `https.*` | Any other properties supported by [https.createServer](https://nodejs.org/dist/latest-v8.x/docs/api/https.html#https_https_createserver_options_requestlistener) can be added to the https object, except `secureProtocol` and `secureOptions` which are set to recommended values. |
32+
33+
If successful, the `create-servers` callback is passed an object with the
34+
following properties:
35+
36+
| Property | Description |
37+
|----------|-------------|
38+
| `http` | The HTTP server that was created, if any |
39+
| `https` | The HTTPS server that was created, if any |
40+
41+
### Certificate normalization
42+
43+
`create-servers` provides some conveniences for `https.ca`, `https.key`, and
44+
`https.cert` config properties. You may use PEM data directly (inside a `Buffer`
45+
or string) or a file name. When using a file name, you may also set an
46+
`https.root` config property to enable using relative paths to cert/key files.
47+
`https.ca` and `https.cert` also support specifying an Array of certs/files.
48+
49+
## NOTE on Security
750
Inspired by [`iojs`][iojs] and a well written [article][article], we have defaulted
851
our [ciphers][ciphers] to support "perfect-forward-security" as well as removing insecure
952
cipher suites from being a possible choice. With this in mind,
1053
be aware that we will no longer support ie6 on windows XP by default.
1154

12-
**http**
55+
## Examples
56+
57+
### http
1358
``` js
1459
var createServers = require('create-servers');
1560

@@ -30,7 +75,7 @@ var servers = createServers(
3075
);
3176
```
3277

33-
**https**
78+
### https
3479
``` js
3580
var servers = createServers(
3681
{
@@ -55,7 +100,7 @@ var servers = createServers(
55100
);
56101
```
57102

58-
**http && https**
103+
### http && https
59104
``` js
60105
var servers = createServers(
61106
{
@@ -86,7 +131,7 @@ var servers = createServers(
86131
);
87132
```
88133

89-
**http && https (different handlers)**
134+
### http && https (different handlers)
90135
``` js
91136
var servers = createServers(
92137
{
@@ -122,8 +167,8 @@ var servers = createServers(
122167
);
123168
```
124169

125-
### Author: [Charlie Robbins](https://github.com/indexzero)
126-
### License: MIT
170+
## Author: [Charlie Robbins](https://github.com/indexzero)
171+
## License: MIT
127172

128173
[article]: https://certsimple.com/blog/a-plus-node-js-ssl
129174
[iojs]: https://github.com/iojs/io.js

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ module.exports = function createServers(options, listening) {
171171

172172
if (typeof timeout === 'number') server.setTimeout(timeout);
173173
args = [server, port];
174-
if (options.https.host) {
175-
args.push(options.https.host);
174+
if (ssl.host) {
175+
args.push(ssl.host);
176176
}
177177

178178
args.push(function listener(err) { onListen('https', err, this); });

0 commit comments

Comments
 (0)