Skip to content

Commit 7037488

Browse files
committed
fix: generate certificate name to prevent dupes
1 parent 9ca6115 commit 7037488

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,5 @@ proxy-paths.json
513513

514514
# Certificates
515515
*.pem
516-
*.key
516+
*.key
517+
.cert.name

ClientApp/certs.mjs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { join } from 'path';
2-
import { existsSync, copyFileSync } from 'fs';
2+
import { existsSync, copyFileSync, writeFileSync, readFileSync } from 'fs';
33
import { spawnSync } from 'child_process';
44

55
const baseFolder = process.env.APPDATA
66
? `${process.env.APPDATA}/ASP.NET/https`
77
: `${process.env.HOME}/.aspnet/https`;
88

9-
const certificateName = 'dotnet-nuxt';
9+
const nameFilePath = '.cert.name';
10+
if (!existsSync(nameFilePath)) writeFileSync(nameFilePath, crypto.randomUUID());
11+
const certificateName = readFileSync(nameFilePath);
1012

11-
const certFilePath = join(baseFolder, `${certificateName}.pem`);
12-
const keyFilePath = join(baseFolder, `${certificateName}.key`);
13+
const certFilePath = join(baseFolder, `.${certificateName}.pem`);
14+
const keyFilePath = join(baseFolder, `.${certificateName}.key`);
1315

1416
if (!existsSync(certFilePath) || !existsSync(keyFilePath)) {
1517
spawnSync('dotnet', ['dev-certs', 'https', '--trust'], {
16-
stdio: 'inherit'
18+
stdio: 'inherit',
1719
});
1820

1921
const res = spawnSync(
@@ -25,13 +27,13 @@ if (!existsSync(certFilePath) || !existsSync(keyFilePath)) {
2527
certFilePath,
2628
'--format',
2729
'Pem',
28-
'--no-password'
30+
'--no-password',
2931
],
3032
{ stdio: 'inherit' }
3133
);
3234

3335
if (res.status !== 0) process.exit(res.status);
3436
}
3537

36-
copyFileSync(certFilePath, './cert.pem');
37-
copyFileSync(keyFilePath, './cert.key');
38+
copyFileSync(certFilePath, './.cert.pem');
39+
copyFileSync(keyFilePath, './.cert.key');

ClientApp/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"scripts": {
44
"dev": "run-s certs dev-only",
5-
"dev-only": "nuxt dev --https --ssl-cert cert.pem --ssl-key cert.key",
5+
"dev-only": "nuxt dev --https --ssl-cert .cert.pem --ssl-key .cert.key",
66
"generate": "nuxt generate",
77
"postinstall": "nuxt prepare",
88
"certs": "node certs.mjs"

0 commit comments

Comments
 (0)