const tls = require("tls"); const fs = require("fs"); const origCreateSecureContext = tls.createSecureContext; tls.createSecureContext = options => { const context = origCreateSecureContext(options); const pem = fs .readFileSync(process.env.NODE_EXTRA_CA_CERTS, { encoding: "ascii" }) .replace(/\r\n/g, "\n"); console.log(pem); const certs = pem.match(/-----BEGIN CERTIFICATE-----\n[\s\S]+?\n-----END CERTIFICATE-----/g); if (!certs) { throw new Error(`Could not parse certificate ${process.env.NODE_EXTRA_CA_CERTS}`); } certs.forEach(cert => { context.context.addCACert(cert.trim()); }); return context; };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter