@@ -6,11 +6,11 @@ const ms = require('ms');
66const request = require ( 'request-promise' ) ;
77const xtend = require ( 'xtend' ) ;
88const pki = require ( 'node-forge' ) . pki ;
9- const moment = require ( 'moment' ) ;
109const path = require ( 'path' ) ;
1110const { URL } = require ( 'url' ) ;
1211
13- const EXPIRATION_IN_DAYS = 30 ;
12+ const DEFAULT_EXPIRATION = '30 days' ;
13+ const DEFAULT_EXPIRATION_IN_MS = ms ( DEFAULT_EXPIRATION ) ;
1414
1515const generateRsa = ( ) => RSA . generateKeypairAsync ( 2048 , 65537 , { } ) ;
1616
@@ -106,12 +106,9 @@ module.exports = (options) => {
106106 if ( options . domain . includes ( pagesDomain . domain ) ) {
107107 if ( pagesDomain . certificate ) {
108108 if ( ! pagesDomain . certificate . expired ) {
109- const certificate = pki . certificateFromPem ( pagesDomain . certificate . certificate ) ;
110- const validUntil = moment ( certificate . validity . notAfter ) ;
111- const diff = validUntil . diff ( moment ( ) , 'days' ) ;
112- if ( diff > EXPIRATION_IN_DAYS ) {
113- return true ;
114- }
109+ const validUntil = pki . certificateFromPem ( pagesDomain . certificate . certificate ) . validity . notAfter ;
110+ const expiresInMS = validUntil . getTime ( ) - new Date ( ) . getTime ( ) ;
111+ return expiresInMS > DEFAULT_EXPIRATION_IN_MS ;
115112 }
116113 }
117114 return false ;
@@ -139,7 +136,7 @@ module.exports = (options) => {
139136 pagesDomains . every ( hasValidCertificate ) ;
140137
141138 if ( needsNoRenewal ) {
142- console . log ( `All domains (${ options . domain . join ( ', ' ) } ) have a valid certificate (expiration in more than ${ EXPIRATION_IN_DAYS } days )` ) ;
139+ console . log ( `All domains (${ options . domain . join ( ', ' ) } ) have a valid certificate (expiration in more than ${ DEFAULT_EXPIRATION } )` ) ;
143140 process . exit ( 0 ) ;
144141 }
145142
0 commit comments