Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Update aspnetcore-https.js
Browse files Browse the repository at this point in the history
  • Loading branch information
wesdevpro committed Nov 19, 2023
1 parent 75628cd commit fd7da0e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/EducationTrail/ClientApp/aspnetcore-https.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
const fs = require('fs');
const spawn = require('child_process').spawn;

const path = require('path');

// Determine the base folder based on the environment
const baseFolder =
process.env.APPDATA !== undefined && process.env.APPDATA !== ''
? `${process.env.APPDATA}/ASP.NET/https`
: `${process.env.HOME}/.aspnet/https`;

// Determine the certificate name based on the environment or provided argument
const certificateArg = process.argv.map(arg => arg.match(/--name=(?<value>.+)/i)).filter(Boolean)[0];
const certificateName = certificateArg ? certificateArg.groups.value : process.env.npm_package_name;

Expand All @@ -17,9 +17,11 @@ if (!certificateName) {
process.exit(-1);
}

// Adjust paths based on the environment
const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
const keyFilePath = path.join(baseFolder, `${certificateName}.key`);

// Check if certificates exist, and generate if not
if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
spawn('dotnet', [
'dev-certs',
Expand All @@ -36,4 +38,4 @@ if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
module.exports = {
certFilePath,
keyFilePath
}
};

0 comments on commit fd7da0e

Please sign in to comment.