From 95f2bd5bc49fb3400465c3cfba39329c7cf27278 Mon Sep 17 00:00:00 2001 From: James Hush Date: Thu, 20 Jun 2019 15:48:22 -0700 Subject: [PATCH] Try this? --- src/certificates.ts | 3 ++- src/index.ts | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/certificates.ts b/src/certificates.ts index 0a6a2f9a..563f38fe 100644 --- a/src/certificates.ts +++ b/src/certificates.ts @@ -15,7 +15,8 @@ const debug = createDebug('devcert:certificates'); * individual domain certificates are signed by the devcert root CA (which was * added to the OS/browser trust stores), they are trusted. */ -export default async function generateDomainCertificate(domain: string | string[]): Promise { +export default async function generateDomainCertificate(domains: string | string[]): Promise { + const domain = Array.isArray(domains) ? domains[0] : domains; mkdirp(pathForDomain(domain)); debug(`Generating private key for ${ domain }`); diff --git a/src/index.ts b/src/index.ts index d643b70b..8f7500b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,8 +35,8 @@ export interface Options { * are Buffers with the contents of the certificate private key and certificate * file, respectively */ -export async function certificateFor(domain: string | string[], options: Options = {}) { - const domains = Array.isArray(domain) ? domain : [domain]; +export async function certificateFor(domains: string | string[], options: Options = {}) { + const domain = Array.isArray(domains) ? domains[0] : domains; debug(`Certificate requested for ${ domains }. Skipping certutil install: ${ Boolean(options.skipCertutilInstall) }. Skipping hosts file: ${ Boolean(options.skipHostsFile) }`); if (options.ui) { @@ -51,23 +51,27 @@ export async function certificateFor(domain: string | string[], options: Options throw new Error('OpenSSL not found: OpenSSL is required to generate SSL certificates - make sure it is installed and available in your PATH'); } - let domainKeyPath = pathForDomain(domains, `private-key.key`); - let domainCertPath = pathForDomain(domains, `certificate.crt`); + let domainKeyPath = pathForDomain(domain, `private-key.key`); + let domainCertPath = pathForDomain(domain, `certificate.crt`); if (!exists(rootCAKeyPath)) { debug('Root CA is not installed yet, so it must be our first run. Installing root CA ...'); await installCertificateAuthority(options); } - if (!exists(pathForDomain(domains, `certificate.crt`))) { + if (!exists(pathForDomain(domain, `certificate.crt`))) { debug(`Can't find certificate file for ${ domains }, so it must be the first request for ${ domains }. Generating and caching ...`); await generateDomainCertificate(domains); } if (!options.skipHostsFile) { - domains.forEach(async (domain) => { + if (Array.isArray(domains)) { + domains.forEach(async (domain) => { + await currentPlatform.addDomainToHostFileIfMissing(domain); + }) + } else { await currentPlatform.addDomainToHostFileIfMissing(domain); - }) + } } debug(`Returning domain certificate`);