@vladmandic/piacme
Advanced tools
Comparing version 0.1.9 to 0.1.10
{ | ||
"name": "@vladmandic/piacme", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "Simple ACME/LetsEncrypt HTTP/SSL Certificate Management", | ||
@@ -31,2 +31,3 @@ "main": "piacme.js", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"bugs": { | ||
@@ -47,3 +48,3 @@ "url": "https://github.com/vladmandic/piacme/issues" | ||
"devDependencies": { | ||
"eslint": "^7.7.0", | ||
"eslint": "^7.8.1", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
@@ -50,0 +51,0 @@ "eslint-plugin-import": "^2.22.0" |
@@ -27,2 +27,3 @@ const log = require('@vladmandic/pilogger'); | ||
fullChain: './cert/fullchain.pem', | ||
renewDays: 10, | ||
}; | ||
@@ -33,2 +34,3 @@ | ||
let initial = true; | ||
let callback = null; | ||
const auth = []; | ||
@@ -227,3 +229,3 @@ | ||
config.days = (ssl.fullChain.notAfter - now) / 1000 / 60 / 60 / 24; | ||
if (config.days > 3) return true; | ||
if (config.days > config.renewDays) return true; | ||
return false; | ||
@@ -240,2 +242,6 @@ } | ||
await createCert(); // used to initialize certificate; typically genrates if cert doesn't exist or is about to expire | ||
if (callback) { | ||
callback(); | ||
callback = null; | ||
} | ||
} | ||
@@ -259,5 +265,6 @@ if (initial) { | ||
async function monitorCert() { | ||
async function monitorCert(f = null) { | ||
callback = f; | ||
await getCert(); | ||
log.state('SSL certificate expires in', config.days.toFixed(1), `days: ${config.days <= 3 ? 'renewing now' : 'skipping renewal'}`); | ||
log.state('SSL certificate expires in', config.days.toFixed(1), `days: ${config.days <= config.renewDays ? 'renewing now' : 'skipping renewal'}`); | ||
setTimeout(() => monitorCert(), 1000 * 60 * 60 * 12); | ||
@@ -264,0 +271,0 @@ } |
@@ -35,2 +35,4 @@ # piacme | ||
fullChain: './cert/fullchain.pem', | ||
// attempt renewal how many days before expiration | ||
renewDays: 10, | ||
}; | ||
@@ -40,3 +42,3 @@ | ||
piacme.init(config); | ||
const { Key, Crt } = await acme.getCert(); | ||
const { Key, Crt } = await piacme.getCert(); | ||
``` | ||
@@ -96,6 +98,13 @@ | ||
piacme.monitorCert(); | ||
```js | ||
piacme.monitorCert();` | ||
``` | ||
(RFE: *Implement monitoring callback that can be used to automatically restart web server as needed*) | ||
or with a provided callback function that `monitorCert()` will call if certificate changes. | ||
```js | ||
function f() { /* do something here */ }; | ||
piacme.monitorCert(f) | ||
``` | ||
To get certificate details, call `parseCert()` and it will parse certificate from the initial object used during `init()` call. | ||
@@ -102,0 +111,0 @@ |
18066
283
123