You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

  1. // This script sets up HTTPS for the application using the ASP.NET Core HTTPS certificate
  2. const fs = require('fs');
  3. const spawn = require('child_process').spawn;
  4. const path = require('path');
  5. const baseFolder =
  6. process.env.APPDATA !== undefined && process.env.APPDATA !== ''
  7. ? `${process.env.APPDATA}/ASP.NET/https`
  8. : `${process.env.HOME}/.aspnet/https`;
  9. const certificateArg = process.argv.map(arg => arg.match(/--name=(?<value>.+)/i)).filter(Boolean)[0];
  10. const certificateName = certificateArg ? certificateArg.groups.value : process.env.npm_package_name;
  11. if (!certificateName) {
  12. console.error('Invalid certificate name. Run this script in the context of an npm/yarn script or pass --name=<<app>> explicitly.')
  13. process.exit(-1);
  14. }
  15. const certFilePath = path.join(baseFolder, `${certificateName}.pem`);
  16. const keyFilePath = path.join(baseFolder, `${certificateName}.key`);
  17. if (!fs.existsSync(baseFolder)) {
  18. fs.mkdirSync(baseFolder, { recursive: true });
  19. }
  20. if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
  21. spawn('dotnet', [
  22. 'dev-certs',
  23. 'https',
  24. '--export-path',
  25. certFilePath,
  26. '--format',
  27. 'Pem',
  28. '--no-password',
  29. ], { stdio: 'inherit', })
  30. .on('exit', (code) => process.exit(code));
  31. }