mkcert.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. // plugin/index.ts
  30. var index_exports = {};
  31. __export(index_exports, {
  32. BaseSource: () => BaseSource,
  33. default: () => index_default
  34. });
  35. module.exports = __toCommonJS(index_exports);
  36. var import_vite = require("vite");
  37. // plugin/lib/constant.ts
  38. var import_node_os = __toESM(require("node:os"));
  39. var import_node_path = __toESM(require("node:path"));
  40. var PKG_NAME = "vite-plugin-mkcert";
  41. var PLUGIN_NAME = PKG_NAME.replace(/-/g, ":");
  42. var PLUGIN_DATA_DIR = import_node_path.default.join(import_node_os.default.homedir(), `.${PKG_NAME}`);
  43. // plugin/lib/util.ts
  44. var import_node_child_process = __toESM(require("node:child_process"));
  45. var import_node_crypto = __toESM(require("node:crypto"));
  46. var import_node_fs = __toESM(require("node:fs"));
  47. var import_node_os2 = __toESM(require("node:os"));
  48. var import_node_path2 = __toESM(require("node:path"));
  49. var import_node_util = __toESM(require("node:util"));
  50. var exists = async (filePath) => {
  51. try {
  52. await import_node_fs.default.promises.access(filePath);
  53. return true;
  54. } catch (_error) {
  55. return false;
  56. }
  57. };
  58. var mkdir = async (dirname) => {
  59. const isExist = await exists(dirname);
  60. if (!isExist) {
  61. await import_node_fs.default.promises.mkdir(dirname, { recursive: true });
  62. }
  63. };
  64. var ensureDirExist = async (filePath, strip = false) => {
  65. const dirname = strip ? import_node_path2.default.dirname(filePath) : filePath;
  66. await mkdir(dirname);
  67. };
  68. var readFile = async (filePath) => {
  69. const isExist = await exists(filePath);
  70. return isExist ? (await import_node_fs.default.promises.readFile(filePath)).toString() : void 0;
  71. };
  72. var writeFile = async (filePath, data) => {
  73. await ensureDirExist(filePath, true);
  74. await import_node_fs.default.promises.writeFile(filePath, data);
  75. await import_node_fs.default.promises.chmod(filePath, 511);
  76. };
  77. var readDir = async (source) => {
  78. return import_node_fs.default.promises.readdir(source);
  79. };
  80. var copyDir = async (source, dest) => {
  81. try {
  82. await import_node_fs.default.promises.cp(source, dest, {
  83. recursive: true
  84. });
  85. } catch (error) {
  86. console.log(`${PLUGIN_NAME}:`, error);
  87. }
  88. };
  89. var exec = async (cmd, options) => {
  90. return import_node_util.default.promisify(import_node_child_process.default.exec)(cmd, options);
  91. };
  92. var isIPV4 = (family) => {
  93. return family === "IPv4" || family === 4;
  94. };
  95. var getLocalV4Ips = () => {
  96. const interfaceDict = import_node_os2.default.networkInterfaces();
  97. const addresses = [];
  98. for (const key in interfaceDict) {
  99. const interfaces = interfaceDict[key];
  100. if (interfaces) {
  101. for (const item of interfaces) {
  102. if (isIPV4(item.family)) {
  103. addresses.push(item.address);
  104. }
  105. }
  106. }
  107. }
  108. return addresses;
  109. };
  110. var getDefaultHosts = () => {
  111. return ["localhost", ...getLocalV4Ips()];
  112. };
  113. var getHash = async (filePath) => {
  114. const content = await readFile(filePath);
  115. if (content) {
  116. const hash = import_node_crypto.default.createHash("sha256");
  117. hash.update(content);
  118. return hash.digest("hex");
  119. }
  120. return void 0;
  121. };
  122. var isObj = (obj) => Object.prototype.toString.call(obj) === "[object Object]";
  123. var mergeObj = (target, source) => {
  124. if (!(isObj(target) && isObj(source))) {
  125. return target;
  126. }
  127. for (const key in source) {
  128. if (Object.prototype.hasOwnProperty.call(source, key)) {
  129. const targetValue = target[key];
  130. const sourceValue = source[key];
  131. if (isObj(targetValue) && isObj(sourceValue)) {
  132. mergeObj(targetValue, sourceValue);
  133. } else {
  134. target[key] = sourceValue;
  135. }
  136. }
  137. }
  138. };
  139. var deepMerge = (target, ...source) => {
  140. return source.reduce((a, b) => mergeObj(a, b), target);
  141. };
  142. var prettyLog = (obj) => {
  143. return JSON.stringify(obj, null, 2);
  144. };
  145. var escapeStr = (path5) => {
  146. return `"${path5}"`;
  147. };
  148. // plugin/mkcert/index.ts
  149. var import_node_path4 = __toESM(require("node:path"));
  150. var import_node_process = __toESM(require("node:process"));
  151. var import_picocolors = __toESM(require("picocolors"));
  152. // plugin/lib/logger.ts
  153. var import_debug = __toESM(require("debug"));
  154. var debug = (0, import_debug.default)(PLUGIN_NAME);
  155. // plugin/mkcert/config.ts
  156. var import_node_path3 = __toESM(require("node:path"));
  157. var CONFIG_FILE_NAME = "config.json";
  158. var Config = class {
  159. /**
  160. * The mkcert version
  161. */
  162. version;
  163. record;
  164. configFilePath;
  165. constructor({ savePath }) {
  166. this.configFilePath = import_node_path3.default.resolve(savePath, CONFIG_FILE_NAME);
  167. }
  168. async init() {
  169. const str = await readFile(this.configFilePath);
  170. const options = str ? JSON.parse(str) : void 0;
  171. if (options) {
  172. this.version = options.version;
  173. this.record = options.record;
  174. }
  175. }
  176. async serialize() {
  177. await writeFile(this.configFilePath, prettyLog(this));
  178. }
  179. // deep merge
  180. async merge(obj) {
  181. const currentStr = prettyLog(this);
  182. deepMerge(this, obj);
  183. const nextStr = prettyLog(this);
  184. debug(
  185. `Receive parameter
  186. ${prettyLog(
  187. obj
  188. )}
  189. Update config from
  190. ${currentStr}
  191. to
  192. ${nextStr}`
  193. );
  194. await this.serialize();
  195. }
  196. getRecord() {
  197. return this.record;
  198. }
  199. getVersion() {
  200. return this.version;
  201. }
  202. };
  203. var config_default = Config;
  204. // plugin/lib/request.ts
  205. var import_axios = __toESM(require("axios"));
  206. var request = import_axios.default.create();
  207. request.interceptors.response.use(
  208. (res) => {
  209. return res;
  210. },
  211. (error) => {
  212. debug("Request error: %o", error);
  213. return Promise.reject(error);
  214. }
  215. );
  216. var request_default = request;
  217. // plugin/mkcert/downloader.ts
  218. var Downloader = class _Downloader {
  219. static create() {
  220. return new _Downloader();
  221. }
  222. constructor() {
  223. }
  224. async download(downloadUrl, savedPath) {
  225. debug("Downloading the mkcert executable from %s", downloadUrl);
  226. const { data } = await request_default.get(downloadUrl, {
  227. responseType: "arraybuffer"
  228. });
  229. await writeFile(savedPath, data);
  230. debug("The mkcert has been saved to %s", savedPath);
  231. }
  232. };
  233. var downloader_default = Downloader;
  234. // plugin/mkcert/record.ts
  235. var Record = class {
  236. config;
  237. constructor(options) {
  238. this.config = options.config;
  239. }
  240. getHosts() {
  241. return this.config.getRecord()?.hosts;
  242. }
  243. getHash() {
  244. return this.config.getRecord()?.hash;
  245. }
  246. contains(hosts) {
  247. const oldHosts = this.getHosts();
  248. if (!oldHosts) {
  249. return false;
  250. }
  251. for (const host of hosts) {
  252. if (!oldHosts.includes(host)) {
  253. return false;
  254. }
  255. }
  256. return true;
  257. }
  258. // whether the files has been tampered with
  259. equal(hash) {
  260. const oldHash = this.getHash();
  261. if (!oldHash) {
  262. return false;
  263. }
  264. return oldHash.key === hash.key && oldHash.cert === hash.cert;
  265. }
  266. async update(record) {
  267. await this.config.merge({ record });
  268. }
  269. };
  270. var record_default = Record;
  271. // plugin/mkcert/source.ts
  272. var BaseSource = class {
  273. getPlatformIdentifier() {
  274. const arch = process.arch === "x64" ? "amd64" : process.arch;
  275. return process.platform === "win32" ? `windows-${arch}.exe` : `${process.platform}-${arch}`;
  276. }
  277. };
  278. var GithubSource = class _GithubSource extends BaseSource {
  279. static create() {
  280. return new _GithubSource();
  281. }
  282. constructor() {
  283. super();
  284. }
  285. async getSourceInfo() {
  286. const { data } = await request_default({
  287. method: "GET",
  288. url: "https://api.github.com/repos/FiloSottile/mkcert/releases/latest"
  289. });
  290. const platformIdentifier = this.getPlatformIdentifier();
  291. const version = data.tag_name;
  292. const downloadUrl = data.assets.find(
  293. (item) => item.name.includes(platformIdentifier)
  294. )?.browser_download_url;
  295. if (!(version && downloadUrl)) {
  296. return void 0;
  297. }
  298. return {
  299. downloadUrl,
  300. version
  301. };
  302. }
  303. };
  304. var CodingSource = class _CodingSource extends BaseSource {
  305. static CODING_API = "https://e.coding.net/open-api";
  306. static CODING_AUTHORIZATION = "token 000f7831ec425079439b0f55f55c729c9280d66e";
  307. static CODING_PROJECT_ID = 8524617;
  308. static REPOSITORY = "mkcert";
  309. static create() {
  310. return new _CodingSource();
  311. }
  312. constructor() {
  313. super();
  314. }
  315. async request(data) {
  316. return request_default({
  317. data,
  318. method: "POST",
  319. url: _CodingSource.CODING_API,
  320. headers: {
  321. Authorization: _CodingSource.CODING_AUTHORIZATION
  322. }
  323. });
  324. }
  325. /**
  326. * Get filename of Coding.net artifacts
  327. *
  328. * @see https://liuweigl.coding.net/p/github/artifacts/885241/generic/packages
  329. *
  330. * @returns name
  331. */
  332. getPackageName() {
  333. return `mkcert-${this.getPlatformIdentifier()}`;
  334. }
  335. async getSourceInfo() {
  336. const { data: VersionData } = await this.request({
  337. Action: "DescribeArtifactVersionList",
  338. ProjectId: _CodingSource.CODING_PROJECT_ID,
  339. Repository: _CodingSource.REPOSITORY,
  340. Package: this.getPackageName(),
  341. PageSize: 1
  342. });
  343. const version = VersionData.Response.Data?.InstanceSet[0]?.Version;
  344. if (!version) {
  345. return void 0;
  346. }
  347. const { data: FileData } = await this.request({
  348. Action: "DescribeArtifactFileDownloadUrl",
  349. ProjectId: _CodingSource.CODING_PROJECT_ID,
  350. Repository: _CodingSource.REPOSITORY,
  351. Package: this.getPackageName(),
  352. PackageVersion: version
  353. });
  354. const downloadUrl = FileData.Response.Url;
  355. if (!downloadUrl) {
  356. return void 0;
  357. }
  358. return {
  359. downloadUrl,
  360. version
  361. };
  362. }
  363. };
  364. // plugin/mkcert/version.ts
  365. var parseVersion = (version) => {
  366. const str = version.trim().replace(/v/i, "");
  367. return str.split(".");
  368. };
  369. var VersionManger = class {
  370. config;
  371. constructor(props) {
  372. this.config = props.config;
  373. }
  374. async update(version) {
  375. try {
  376. await this.config.merge({ version });
  377. } catch (err) {
  378. debug("Failed to record mkcert version info: %o", err);
  379. }
  380. }
  381. compare(version) {
  382. const currentVersion = this.config.getVersion();
  383. if (!currentVersion) {
  384. return {
  385. currentVersion,
  386. nextVersion: version,
  387. breakingChange: false,
  388. shouldUpdate: true
  389. };
  390. }
  391. let breakingChange = false;
  392. let shouldUpdate = false;
  393. const newVersion = parseVersion(version);
  394. const oldVersion = parseVersion(currentVersion);
  395. for (let i = 0; i < newVersion.length; i++) {
  396. if (newVersion[i] > oldVersion[i]) {
  397. shouldUpdate = true;
  398. breakingChange = i === 0;
  399. break;
  400. }
  401. }
  402. return {
  403. breakingChange,
  404. shouldUpdate,
  405. currentVersion,
  406. nextVersion: version
  407. };
  408. }
  409. };
  410. var version_default = VersionManger;
  411. // plugin/mkcert/index.ts
  412. var Mkcert = class _Mkcert {
  413. force;
  414. autoUpgrade;
  415. sourceType;
  416. savePath;
  417. logger;
  418. source;
  419. localMkcert;
  420. savedMkcert;
  421. keyFilePath;
  422. certFilePath;
  423. config;
  424. static create(options) {
  425. return new _Mkcert(options);
  426. }
  427. constructor(options) {
  428. const {
  429. force,
  430. autoUpgrade,
  431. source,
  432. mkcertPath,
  433. savePath = PLUGIN_DATA_DIR,
  434. keyFileName = "dev.pem",
  435. certFileName = "cert.pem",
  436. logger
  437. } = options;
  438. this.force = force;
  439. this.logger = logger;
  440. this.autoUpgrade = autoUpgrade;
  441. this.localMkcert = mkcertPath;
  442. this.savePath = import_node_path4.default.resolve(savePath);
  443. this.keyFilePath = import_node_path4.default.resolve(savePath, keyFileName);
  444. this.certFilePath = import_node_path4.default.resolve(savePath, certFileName);
  445. this.sourceType = source || "github";
  446. if (this.sourceType === "github") {
  447. this.source = GithubSource.create();
  448. } else if (this.sourceType === "coding") {
  449. this.source = CodingSource.create();
  450. } else {
  451. this.source = this.sourceType;
  452. }
  453. this.savedMkcert = import_node_path4.default.resolve(
  454. savePath,
  455. import_node_process.default.platform === "win32" ? "mkcert.exe" : "mkcert"
  456. );
  457. this.config = new config_default({ savePath: this.savePath });
  458. }
  459. async getMkcertBinary() {
  460. let binary;
  461. if (this.localMkcert) {
  462. if (await exists(this.localMkcert)) {
  463. binary = this.localMkcert;
  464. } else {
  465. this.logger.error(
  466. import_picocolors.default.red(
  467. `${this.localMkcert} does not exist, please check the mkcertPath parameter`
  468. )
  469. );
  470. }
  471. } else if (await exists(this.savedMkcert)) {
  472. binary = this.savedMkcert;
  473. }
  474. return binary;
  475. }
  476. async checkCAExists() {
  477. const files = await readDir(this.savePath);
  478. return files.some((file) => file.includes("rootCA"));
  479. }
  480. async retainExistedCA() {
  481. if (await this.checkCAExists()) {
  482. return;
  483. }
  484. const mkcertBinary = await this.getMkcertBinary();
  485. const commandStatement = `${escapeStr(mkcertBinary)} -CAROOT`;
  486. debug(`Exec ${commandStatement}`);
  487. const commandResult = await exec(commandStatement);
  488. const caDirPath = import_node_path4.default.resolve(
  489. commandResult.stdout.toString().replace(/\n/g, "")
  490. );
  491. if (caDirPath === this.savePath) {
  492. return;
  493. }
  494. const caDirExists = await exists(caDirPath);
  495. if (!caDirExists) {
  496. return;
  497. }
  498. await copyDir(caDirPath, this.savePath);
  499. }
  500. async getCertificate() {
  501. const key = await readFile(this.keyFilePath);
  502. const cert = await readFile(this.certFilePath);
  503. return {
  504. key,
  505. cert
  506. };
  507. }
  508. async createCertificate(hosts) {
  509. const names = hosts.join(" ");
  510. const mkcertBinary = await this.getMkcertBinary();
  511. if (!mkcertBinary) {
  512. debug(
  513. `Mkcert does not exist, unable to generate certificate for ${names}`
  514. );
  515. }
  516. await ensureDirExist(this.savePath);
  517. await this.retainExistedCA();
  518. const cmd = `${escapeStr(mkcertBinary)} -install -key-file ${escapeStr(
  519. this.keyFilePath
  520. )} -cert-file ${escapeStr(this.certFilePath)} ${names}`;
  521. await exec(cmd, {
  522. env: {
  523. ...import_node_process.default.env,
  524. CAROOT: this.savePath,
  525. JAVA_HOME: void 0
  526. }
  527. });
  528. this.logger.info(
  529. `The list of generated files:
  530. ${this.keyFilePath}
  531. ${this.certFilePath}`
  532. );
  533. }
  534. getLatestHash = async () => {
  535. return {
  536. key: await getHash(this.keyFilePath),
  537. cert: await getHash(this.certFilePath)
  538. };
  539. };
  540. async regenerate(record, hosts) {
  541. await this.createCertificate(hosts);
  542. const hash = await this.getLatestHash();
  543. record.update({ hosts, hash });
  544. }
  545. async init() {
  546. await ensureDirExist(this.savePath);
  547. await this.config.init();
  548. const mkcertBinary = await this.getMkcertBinary();
  549. if (!mkcertBinary) {
  550. await this.initMkcert();
  551. } else if (this.autoUpgrade) {
  552. await this.upgradeMkcert();
  553. }
  554. }
  555. async getSourceInfo() {
  556. const sourceInfo = await this.source.getSourceInfo();
  557. if (!sourceInfo) {
  558. const message = typeof this.sourceType === "string" ? `Unsupported platform. Unable to find a binary file for ${import_node_process.default.platform} platform with ${import_node_process.default.arch} arch on ${this.sourceType === "github" ? "https://github.com/FiloSottile/mkcert/releases" : "https://liuweigl.coding.net/p/github/artifacts?hash=8d4dd8949af543159c1b5ac71ff1ff72"}` : 'Please check your custom "source", it seems to return invalid result';
  559. throw new Error(message);
  560. }
  561. return sourceInfo;
  562. }
  563. async initMkcert() {
  564. const sourceInfo = await this.getSourceInfo();
  565. debug("The mkcert does not exist, download it now");
  566. await this.downloadMkcert(sourceInfo.downloadUrl, this.savedMkcert);
  567. }
  568. async upgradeMkcert() {
  569. const versionManger = new version_default({ config: this.config });
  570. const sourceInfo = await this.getSourceInfo();
  571. if (!sourceInfo) {
  572. this.logger.error(
  573. "Can not obtain download information of mkcert, update skipped"
  574. );
  575. return;
  576. }
  577. const versionInfo = versionManger.compare(sourceInfo.version);
  578. if (!versionInfo.shouldUpdate) {
  579. debug("Mkcert is kept latest version, update skipped");
  580. return;
  581. }
  582. if (versionInfo.breakingChange) {
  583. debug(
  584. "The current version of mkcert is %s, and the latest version is %s, there may be some breaking changes, update skipped",
  585. versionInfo.currentVersion,
  586. versionInfo.nextVersion
  587. );
  588. return;
  589. }
  590. debug(
  591. "The current version of mkcert is %s, and the latest version is %s, mkcert will be updated",
  592. versionInfo.currentVersion,
  593. versionInfo.nextVersion
  594. );
  595. await this.downloadMkcert(sourceInfo.downloadUrl, this.savedMkcert);
  596. versionManger.update(versionInfo.nextVersion);
  597. }
  598. async downloadMkcert(sourceUrl, distPath) {
  599. const downloader = downloader_default.create();
  600. await downloader.download(sourceUrl, distPath);
  601. }
  602. async renew(hosts) {
  603. const record = new record_default({ config: this.config });
  604. if (this.force) {
  605. debug("Certificate is forced to regenerate");
  606. await this.regenerate(record, hosts);
  607. }
  608. if (!record.contains(hosts)) {
  609. debug(
  610. `The hosts changed from [${record.getHosts()}] to [${hosts}], start regenerate certificate`
  611. );
  612. await this.regenerate(record, hosts);
  613. return;
  614. }
  615. const hash = await this.getLatestHash();
  616. if (!record.equal(hash)) {
  617. debug(
  618. `The hash changed from ${prettyLog(record.getHash())} to ${prettyLog(
  619. hash
  620. )}, start regenerate certificate`
  621. );
  622. await this.regenerate(record, hosts);
  623. return;
  624. }
  625. debug("Neither hosts nor hash has changed, skip regenerate certificate");
  626. }
  627. /**
  628. * Get certificates
  629. *
  630. * @param hosts host collection
  631. * @returns cretificates
  632. */
  633. async install(hosts) {
  634. if (hosts.length) {
  635. await this.renew(hosts);
  636. }
  637. return await this.getCertificate();
  638. }
  639. };
  640. var mkcert_default = Mkcert;
  641. // plugin/index.ts
  642. var plugin = (options = {}) => {
  643. return {
  644. name: PLUGIN_NAME,
  645. apply: "serve",
  646. config: async ({ server = {}, logLevel }) => {
  647. if (typeof server.https === "boolean" && server.https === false) {
  648. return;
  649. }
  650. const { hosts = [], ...mkcertOptions } = options;
  651. const logger = (0, import_vite.createLogger)(logLevel, {
  652. prefix: PLUGIN_NAME
  653. });
  654. const mkcert = mkcert_default.create({
  655. logger,
  656. ...mkcertOptions
  657. });
  658. await mkcert.init();
  659. const allHosts = [...getDefaultHosts(), ...hosts];
  660. if (typeof server.host === "string") {
  661. allHosts.push(server.host);
  662. }
  663. const uniqueHosts = Array.from(new Set(allHosts)).filter(Boolean);
  664. const certificate = await mkcert.install(uniqueHosts);
  665. const httpsConfig = {
  666. key: certificate.key && Buffer.from(certificate.key),
  667. cert: certificate.cert && Buffer.from(certificate.cert)
  668. };
  669. return {
  670. server: {
  671. https: httpsConfig
  672. },
  673. preview: {
  674. https: httpsConfig
  675. }
  676. };
  677. }
  678. };
  679. };
  680. var index_default = plugin;
  681. // Annotate the CommonJS export names for ESM import in node:
  682. 0 && (module.exports = {
  683. BaseSource
  684. });
  685. //# sourceMappingURL=mkcert.js.map