Skip to content

Commit

Permalink
Try this?
Browse files Browse the repository at this point in the history
  • Loading branch information
James Hush authored and James Zetlen committed Nov 21, 2019
1 parent 1c77d6c commit 08038ba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export default async function generateDomainCertificate(domains: string | string[]): Promise<void> {
const domain = Array.isArray(domains) ? domains[0] : domains;
mkdirp(pathForDomain(domain));

debug(`Generating private key for ${ domain }`);
Expand Down
18 changes: 11 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1232,17 +1232,17 @@ trim-off-newlines@^1.0.0:

tslib@^1.10.0:
version "1.10.0"
resolved "https://system1.jfrog.io/system1/api/npm/npm-virtual/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha1-w8GflZc/sKYpc/sJ2Q2WHuQ+XIo=
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"
integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==

typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.9.2:
version "2.9.2"
resolved "https://system1.jfrog.io/system1/api/npm/npm-virtual/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha1-HL9h0F1rliaSROtqO85L2RTg8Aw=
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.9.2.tgz#1cbf61d05d6b96269244eb6a3bce4bd914e0f00c"
integrity sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==

uglify-js@^2.6:
version "2.8.18"
Expand Down

0 comments on commit 08038ba

Please sign in to comment.