Verified Commit 25ae68c7 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add ability to pass custom domains

Committing this in its own branch but I won’t be merging this into master as I don’t see a use case for it at the moment given that if used with a service like ngrok, it results in certificate warnings. The way have publicly-accessible staging is to use ngrok and integrate with automatic Let’s Encrypt certificate generation using Greenlock.js.
parent bc278d99
#!/usr/bin/env node
require('../index.js')
//
// Usage: nodecert [domain1] [domain2] […]
//
// If additional domains are provided – e.g., for staging with ngrok (https://ngrok.com/) –
// they are added to the certificate alongside localhost, 127.0.0.1, and ::1.
const additionalDomainsIfAny = process.argv.splice(2)
require('../index.js').apply(null, [{domains: additionalDomainsIfAny}])
......@@ -12,7 +12,8 @@ const mkcertBinary = mkcertBinaryForThisMachine()
const syswidecas = require('syswide-cas')
module.exports = function () {
module.exports = function (nodecertOptions = {}) {
// Create certificates.
if (!allOK()) {
......@@ -44,11 +45,18 @@ module.exports = function () {
// Create the local certificate.
console.log(' 📜 [nodecert] Creating TLS certificates using mkcert…\n')
const createCertificateArguments = [
let createCertificateArguments = [
`-key-file=${path.join(nodecertDir, 'localhost-key.pem')}`,
`-cert-file=${path.join(nodecertDir, 'localhost.pem')}`,
'localhost', '127.0.0.1', '::1'
]
// If any additional domains have been passed (for example, ngrok staging domains),
// add those to the arguments list.
if (nodecertOptions.domains !== undefined && nodecertOptions.domains instanceof Array === true) {
createCertificateArguments = createCertificateArguments.concat(nodecertOptions.domains)
}
console.log('__(mkcert)____________________________________________________________________________________________________________\n')
childProcess.execFileSync(mkcertBinary, createCertificateArguments, options)
console.log('──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n')
......@@ -64,7 +72,7 @@ module.exports = function () {
}
addRootStoreToNode()
}()
}
// Write to stdout without a newline
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment