{"name":"create-servers","version":"2.0.1","description":"Create an http AND/OR an https server and call the same request handler.","main":"index.js","scripts":{"test":"node test/create-servers-test.js"},"repository":{"type":"git","url":"git+https://github.com/indexzero/create-servers.git"},"keywords":["http","https","utility"],"author":{"name":"Charlie Robbins","email":"charlie.robbins@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/indexzero/create-servers/issues"},"homepage":"https://github.com/indexzero/create-servers","dependencies":{"connected":"~0.0.2","errs":"~0.3.0"},"devDependencies":{"tape":"~2.14.0"},"gitHead":"d8c2ca45f43fb25fda7a5cc089e8995686b3bb5c","_id":"create-servers@2.0.1","_shasum":"f8be53ecfd684b65ebb592a6868d85b9e844249a","_from":".","_npmVersion":"3.7.1","_nodeVersion":"4.2.2","_npmUser":{"name":"indexzero","email":"charlie.robbins@gmail.com"},"maintainers":[{"name":"indexzero","email":"charlie.robbins@gmail.com"},{"name":"v1","email":"npm@3rd-Eden.com"},{"name":"3rdeden","email":"npm@3rd-Eden.com"},{"name":"swaagie","email":"info@martijnswaagman.nl"}],"dist":{"shasum":"f8be53ecfd684b65ebb592a6868d85b9e844249a","tarball":"http://registry-npm.ywwl.com/create-servers/download/create-servers-2.0.1.tgz","integrity":"sha512-LlP2IZ8/3zgGBwaB6cLKeSdEmpGpOoUYjigfBjER44UAb8ZKZsIO2KyVlfsMsrWLEH3Wi4bsqGGIJHSp7eqNKw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFbML6T0L/z5MfuyGOfRdP4p9gybyRHDC0KQBY0OMq7VAiAlxDiHyksXm5+fANNI6gMrCEU0qQVtxXNBm1+Iv7kq6w=="}],"size":6763,"noattachment":false,"key":"/create-servers/-/create-servers-2.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-5-east.internal.npmjs.com","tmp":"tmp/create-servers-2.0.1.tgz_1455581253863_0.5420594229362905"},"directories":{},"readme":"# create-servers\n\nCreate an http AND/OR an https server and call the same request handler.\n\n## Usage\n\nThe `create-servers` module exports a function that takes a config object and\na node-style callback. The config object must have at minimum an `http` or\n`https` property (or both). The following config properties are supported:\n\n| Property                 | Description                                                                                                                                                                                                                                                                           |\n| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `handler`                | Request handler to be used for any server, unless overridden specifically with `http.handler` or `https.handler`.                                                                                                                                                                     |\n| `timeout`                | Socket timeout in milliseconds for any server, unless overridden with `http.timeout` or `https.timeout`. Defaults to the node default of 2 minutes.                                                                                                                                   |\n| `keepAliveTimeout`       | Milliseconds of activity before sockets are destroyed. Defaults to the node default value (currently 5 seconds). |\n| `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. You may also use an Array to start multiple servers.                                                                              |\n| `http.port`              | TCP port for the HTTP server. Defaults to `80`.                                                                                                                                                                                                                                       |\n| `http.host`              | The address the HTTP server is bound to. Defaults to `::` or `0.0.0.0`.                                                                                                                                                                                                               |\n| `http.timeout`           | Socket timeout in milliseconds for the server. If unspecified, the top-level `timeout` configuration is used.                                                                                                                                                                         |\n| `http.keepAliveTimeout`  | Overrides the top-level keepAliveTimeout setting if specified. |\n| `http.handler`           | Handler for HTTP requests. If you want to share a handler with all servers, use a top-level `handler` config property instead.                                                                                                                                                        |\n| `https`                  | Optional object. If present, an HTTPS server is started. You may start multiple HTTPS servers by passing an array of objects                                                                                                                                                          |\n| `https.port`             | TCP port for the HTTPS server. Defaults to `443`.                                                                                                                                                                                                                                     |\n| `https.host`             | The address the HTTPS server is bound to. Defaults to `::` or `0.0.0.0`.                                                                                                                                                                                                              |\n| `https.timeout`          | Socket timeout in milliseconds for the server. If unspecified, the top-level `timeout` configuration is used.                                                                                                                                                                         |\n| `https.keepAliveTimeout`  | Overrides the top-level keepAliveTimeout setting if specified. |\n| `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.                                                                                                     |\n| `https.honorCipherOrder` | If true, prefer the server's specified cipher order instead of the client's. Defaults to `false`.                                                                                                                                                                                     |\n| `https.root`             | Root directory for certificate/key files. See [Certificate normalization](#certificate-normalization) for more details.                                                                                                                                                               |\n| `https.key`              | PEM/file path for the server's private key. See [Certificate normalization](#certificate-normalization) for more details.                                                                                                                                                             |\n| `https.cert`             | PEM/file path(s) for the server's certificate. See [Certificate normalization](#certificate-normalization) for more details.                                                                                                                                                          |\n| `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. |\n| `https.sni`              | See [SNI Support](#sni-support).                                                                                                                                                                                                                                                      |\n| `https.handler`          | Handler for HTTPS requests. If you want to share a handler with all servers, use a top-level `handler` config property instead.                                                                                                                                                       |\n| `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.   |\n| `http2`                  | Optional object. If present, an HTTP/2 server is started. You may start multiple HTTP/2 servers by passing an array of objects                                                                                                                                                        |\n| `http2.allowHTTP1`       | Enable [ALPN negotiation] allowing support for both HTTPS and HTTP/2 on the same socket.                                                                                                                                                                                              |\n| `http2.*`                | The same `https` security options are allowed, as well as any other properties supported by [http2.createSecureServer](https://nodejs.org/dist/latest-v8.x/docs/api/http2.html#http2_http2_createsecureserver_options_onrequesthandler).                                              |\n\nIf successful, the `create-servers` callback is passed an object with the\nfollowing properties:\n\n| Property | Description                                                                                     |\n| -------- | ----------------------------------------------------------------------------------------------- |\n| `http`   | The HTTP server that was created, if any. If creating multiple servers, this will be an Array.  |\n| `https`  | The HTTPS server that was created, if any. If creating multiple servers, this will be an Array. |\n\n### Certificate Normalization\n\n`create-servers` provides some conveniences for `https.ca`, `https.key`, and\n`https.cert` config properties. You may use PEM data directly (inside a `Buffer`\nor string) or a file name. When using a file name, you must also set an\n`https.root` config property if using relative paths to cert/key files.\n\n`https.ca`, `https.cert`, and `https.key` also support specifying an Array.\nGiven an array for `cert`, you must have a matching array for `key` so each cert\ncan be matched with its private key.\n\n```js\nconst createServers = require('create-servers');\n\ncreateServers({\n  https: {\n    root: '/cert/path',\n    cert: ['cert1.crt', 'cert2.crt'],\n    key: ['cert1.key', 'cert2.key']\n  }\n}, err => {\n  // ...\n})\n```\n\nIf you have a cert that is signed by an intermediate CA, your server will need\nto append the untrusted parts of the CA chain with your cert. To make this more\nconvenient, `create-servers` lets you use an array to automatically create a\nchain.\n\n```js\nconst createServers = require('create-servers');\n\ncreateServers({\n  https: {\n    root: '/cert/path',\n    cert: ['cert.crt', 'intermediate.crt'],\n    key: 'cert.key'\n  }\n}, err => {\n  // ...\n})\n```\n\nIf you are specifying multiple certs _and_ you want to create chains for each,\nuse an array of arrays.\n\n```js\nconst createServers = require('create-servers');\n\ncreateServers({\n  https: {\n    root: '/cert/path',\n    cert: [['cert1.crt', 'intermediate.crt'], 'cert2.crt'],\n    key: ['cert1.key', 'cert2.key']\n  }\n}, err => {\n  // ...\n})\n```\n\n### SNI Support\n\n[Server Name Indication](https://en.wikipedia.org/wiki/Server_Name_Indication),\nor SNI, lets HTTPS clients announce which hostname they wish to connect to\nbefore the server sends its certificate, enabling the use of the same server for\nmultiple hosts. Although `SNICallback` can be used to support this, you lose the\nconvenient certificate normalization provided by `create-servers`. The `sni`\nconfig option provides an easier way.\n\nThe `sni` option is an object with each key being a supported hostname and each\nvalue being a subset of the HTTPS settings listed above. HTTPS settings defined\nat the top level are used as defaults for the hostname-specific settings.\n\n```js\nconst createServers = require('create-servers');\n\ncreateServers(\n  {\n    https: {\n      port: 443,\n      sni: {\n        'example1.com': {\n          key: '/certs/private/example1.com.key',\n          cert: '/certs/public/example1.com.crt'\n        },\n        'example2.com': {\n          key: '/certs/private/example2.com.key',\n          cert: '/certs/public/example2.com.crt'\n        }\n      }\n    },\n    handler: function (req, res) {\n      res.end('Hello');\n    }\n  },\n  function (errs) {\n    if (errs) {\n      return console.log(errs.https);\n    }\n\n    console.log('Listening on 443');\n  }\n);\n```\n\nUse `*` in the hostname for wildcard certs. Example: `*.example.com`. The\nfollowing settings are supported in the host-specific configuration:\n\n* key\n* cert\n* ca\n* ciphers\n* honorCipherOrder\n* Anything else supported by [`tls.createSecureContext`](https://nodejs.org/dist/latest-v8.x/docs/api/tls.html#tls_tls_createsecurecontext_options)\n\n## NOTE on Security\nInspired by [`iojs`][iojs] and a well written [article][article], we have defaulted\nour [ciphers][ciphers] to support \"perfect-forward-security\" as well as removing insecure\ncipher suites from being a possible choice. With this in mind,\nbe aware that we will no longer support ie6 on windows XP by default.\n\n## Examples\n\n### http\n\n```js\nvar createServers = require('create-servers');\n\nvar servers = createServers(\n  {\n    http: 80,\n    handler: function (req, res) {\n      res.end('http only');\n    }\n  },\n  function (errs) {\n    if (errs) {\n      return console.log(errs.http);\n    }\n\n    console.log('Listening on 80');\n  }\n);\n```\n\n### https\n\n```js\nvar servers = createServers(\n  {\n    https: {\n      port: 443,\n      root: '/path/to/ssl/files',\n      key: 'your-key.pem',\n      cert: 'your-cert.pem',\n      ca: 'your-ca.pem' // Can be an Array of CAs\n    },\n    handler: function (req, res) {\n      res.end('https only');\n    }\n  },\n  function (errs) {\n    if (errs) {\n      return console.log(errs.https);\n    }\n\n    console.log('Listening on 443');\n  }\n);\n```\n\n### http && https\n\n```js\nvar servers = createServers(\n  {\n    http: 80,\n    https: {\n      port: 443,\n      root: '/path/to/ssl/files',\n      key: 'your-key.pem',\n      cert: 'your-cert.pem',\n      ca: 'your-ca.pem' // Can be an Array of CAs\n    },\n    handler: function (req, res) {\n      res.end('http AND https');\n    }\n  },\n  function (errs, servers) {\n    if (errs) {\n      return Object.keys(errs).forEach(function (key) {\n        console.log('Error ' + key + ': ' + errs[key]);\n        if (servers[key]) {\n          servers[key].close();\n        }\n      });\n    }\n\n    console.log('Listening on 80 and 443');\n  }\n);\n```\n\n### http && https (different handlers)\n\n```js\nvar servers = createServers(\n  {\n    http: {\n      port: 80,\n      handler: function (req, res) {\n        res.end('http');\n      }\n    },\n    https: {\n      port: 443,\n      root: '/path/to/ssl/files',\n      key: 'your-key.pem',\n      cert: 'your-cert.pem',\n      ca: 'your-ca.pem', // Can be an Array of CAs\n      handler: function (req, res) {\n        res.end('https');\n      }\n    }\n  },\n  function (errs, servers) {\n    if (errs) {\n      return Object.keys(errs).forEach(function (key) {\n        console.log('Error ' + key + ': ' + errs[key]);\n        if (servers[key]) {\n          servers[key].close();\n        }\n      });\n    }\n\n    console.log('Listening on 80 and 443');\n  }\n);\n```\n\n## Author: [Charlie Robbins](https://github.com/indexzero)\n## License: MIT\n\n[article]: https://certsimple.com/blog/a-plus-node-js-ssl\n[iojs]: https://github.com/iojs/io.js\n[ciphers]: https://iojs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener\n[ALPN negotiation]: https://nodejs.org/api/http2.html#http2_alpn_negotiation\n","publish_time":1455581257559,"_cnpm_publish_time":1455581257559,"dist-tags":{"latest":"3.3.0"}}