Skip to content

Commit

Permalink
Update vite.config.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric authored Nov 8, 2024
1 parent d1cc740 commit e160e69
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions MyApp.Client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,33 @@ const baseFolder =
? `${env.APPDATA}/ASP.NET/https`
: `${env.HOME}/.aspnet/https`;

const certificateArg = process.argv.map(arg => arg.match(/--name=(?<value>.+)/i)).filter(Boolean)[0];
const certificateName = certificateArg ? certificateArg!.groups!.value : "myapp.client";

if (!certificateName) {
console.error('Invalid certificate name. Run this script in the context of an npm/yarn script or pass --name=<<app>> explicitly.')
process.exit(-1);
}

const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

console.log(`Certificate path: ${certFilePath}`);

if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
if (0 !== child_process.spawnSync('dotnet', [
'dev-certs',
'https',
'--verbose',
'--trust'
], { stdio: 'inherit', }).status) {

// mkdir to fix dotnet dev-certs error 3 https://github.com/dotnet/aspnetcore/issues/58330
if (!fs.existsSync(baseFolder)) {
fs.mkdirSync(baseFolder, { recursive: true });
}
if (
0 !==
child_process.spawnSync(
"dotnet",
[
"dev-certs",
"https",
"--export-path",
certFilePath,
"--format",
"Pem",
"--no-password",
],
{ stdio: "inherit" }
).status
) {
throw new Error("Could not create certificate.");
}
}
Expand Down

0 comments on commit e160e69

Please sign in to comment.