Skip to content

Instantly share code, notes, and snippets.

@Davisonpro
Created January 13, 2019 11:13
Show Gist options
  • Save Davisonpro/1195b06281624446db2573f4f7f2e2f9 to your computer and use it in GitHub Desktop.
Save Davisonpro/1195b06281624446db2573f4f7f2e2f9 to your computer and use it in GitHub Desktop.
Generate certificate
if ( ! fs.existsSync( key ) || ! fs.existsSync( certificate ) ) {
try {
execSync( 'openssl version', execOptions );
execSync(
`openssl req -x509 -newkey rsa:2048 -keyout ./certs/key.tmp.pem -out ${ certificate } -days 365 -nodes -subj "/C=US/ST=Foo/L=Bar/O=Baz/CN=localhost"`,
execOptions
);
execSync( `openssl rsa -in ./certs/key.tmp.pem -out ${ key }`, execOptions );
execSync( 'rm ./certs/key.tmp.pem', execOptions );
} catch ( error ) {
console.error( error );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment