react-cosmos
Version:
Sandbox for developing and testing UI components in isolation
25 lines (24 loc) • 762 B
JavaScript
import fs from 'fs';
import pem from 'pem';
let _cache;
export async function getHttpsCreds(config) {
const { httpsOptions } = config;
if (httpsOptions)
return {
key: fs.readFileSync(httpsOptions.keyPath, 'utf8'),
cert: fs.readFileSync(httpsOptions.certPath, 'utf8'),
};
if (_cache)
return _cache;
console.log('[Cosmos] Generating HTTPS certificate');
return await new Promise((resolve, reject) => {
pem.createCertificate({ days: 1000, selfSigned: true }, (err, keys) => {
if (err)
reject(err);
else {
_cache = { key: keys.serviceKey, cert: keys.certificate };
resolve(_cache);
}
});
});
}