forked from watson/https-pem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (24 loc) · 893 Bytes
/
Copy pathindex.js
File metadata and controls
31 lines (24 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
const path = require('node:path')
const fs = require('node:fs')
let generator
const keyPath = path.join(__dirname, 'key.pem')
const certPath = path.join(__dirname, 'cert.pem')
// In case npm scripts are disabled, we still want to provide the key and cert
exports.key = fs.existsSync(keyPath) ? fs.readFileSync(keyPath) : null
exports.cert = fs.existsSync(certPath) ? fs.readFileSync(certPath) : null
exports.generate = generate
exports.default = exports
function generate ({ attr, opts } = { attr: [], opts: null }, done) {
if (done == null) {
const promise = new Promise((resolve, reject) => {
generate({ attr, opts }, (err, pems) => {
if (err) return reject(err)
resolve({ key: pems.private, cert: pems.cert })
})
})
return promise
}
if (!generator) generator = require('./generate')
generator.generate(attr, opts, done)
}