From e160e694cea183bbb95c354d7db8590be79c9ab0 Mon Sep 17 00:00:00 2001 From: Darren Reid Date: Fri, 8 Nov 2024 14:53:53 +1100 Subject: [PATCH] Update vite.config.ts --- MyApp.Client/vite.config.ts | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/MyApp.Client/vite.config.ts b/MyApp.Client/vite.config.ts index c57ffa8..93d8e34 100644 --- a/MyApp.Client/vite.config.ts +++ b/MyApp.Client/vite.config.ts @@ -20,24 +20,33 @@ const baseFolder = ? `${env.APPDATA}/ASP.NET/https` : `${env.HOME}/.aspnet/https`; -const certificateArg = process.argv.map(arg => arg.match(/--name=(?.+)/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=<> 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."); } }