A cached pool of https server for domains.
$ npm i https-pool --save
https-pool is useful for getting https server without worry about forging certificates.
Just pass your CA certificate options into HttpsPool, and get a empty https server pool.
const HttpsPool = require("https-pool");
const fs = require("fs");
const httpsPool = new HttpsPool({
commonName: "example",
countryName: "CN",
ST: "SH",
localityName: "SH",
organizationName: "example.com",
OU: "example.com"
});
// You can save the cert and key of root CA to let the client trust it.
const { key, cert } = httpsPool.CA;
Or create a empty https server pool with specific key and cert:
const HttpsPool = require("https-pool");
const fs = require("fs");
const key = fs.readFileSync(path.join(fixtures, "root.key"));
const cert = fs.readFileSync(path.join(fixtures, "root.crt"));
const httpsPool = new HttpsPool({
key,
cert
});
You can get a https server like this ↓. That's enough for common usage. https-pool
will take care of the cache logic, so worrying about your memory is unnecessary.
httpsPool.getServer(
"www.foo.com",
(req, res) => {
// the listener for server.request event
console.log(req.headers);
res.send("ok");
},
_port => {
// callback with a random available port
console.log(typeof _port === "number");
},
// timeout for the new https-server
3000
);
httpsPool.CA
- return as {key, cert} in the format as pem. (You could trust the key and cert on the your client such as browser)
It will create a https pool.
- options
option.timeout
- https server won't close until secure conntection is established within timeout (default 6000)option.max_servers
- max num for https servers the pool cached (default 220)option.key
andoption.cert
- the private key and cert of the root ca which your client trusts or https-pool will create one- If you don't pass
option.key
andoption.cert
, you need to pass these options:option.commonName
- the common name optionoption.countryName
- the country name optionoption.ST
- the ST optionoption.localityName
- the locality name optionoption.organizationName
- the organization name optionoption.OU
- the OU option
It will return a https server if available or will create one and cached.
hostname
- hostname which https server base onlistener
{Function
|Object
} - request event listener or Object type with custom event listenercallback
- callback func with port argtimeout
- timeout for https server in ms
Tell whether the server basing on the hostname exists
hostname
- the hostname server base onreturn {boolean}
Remove the server in the cache
hostname
- the hostname server base on
Free the https server who has no connections when count > max
Clear the https pool forcily
Licensed under the MIT license.