unplugin-https-reverse-proxy 4.0.4 → 4.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +30 -6
  2. package/dist/{chunk-5R33PUJP.js → chunk-7CA3EIIX.js} +681 -223
  3. package/dist/{chunk-2P7SUCQ3.js → chunk-EY3HXBJ4.js} +0 -26
  4. package/dist/chunk-RKHJN6KY.js +53 -0
  5. package/dist/esbuild.cjs +781 -300
  6. package/dist/esbuild.js +3 -2
  7. package/dist/index.cjs +781 -300
  8. package/dist/index.js +3 -2
  9. package/dist/nuxt.cjs +779 -290
  10. package/dist/nuxt.js +5 -9
  11. package/dist/privileged-helper.cjs +668 -0
  12. package/dist/privileged-helper.d.cts +2 -0
  13. package/dist/privileged-helper.d.ts +2 -0
  14. package/dist/privileged-helper.js +641 -0
  15. package/dist/rollup.cjs +781 -300
  16. package/dist/rollup.js +3 -2
  17. package/dist/rspack.cjs +781 -300
  18. package/dist/rspack.js +3 -2
  19. package/dist/utils.cjs +0 -28
  20. package/dist/utils.d.cts +1 -3
  21. package/dist/utils.d.ts +1 -3
  22. package/dist/utils.js +1 -5
  23. package/dist/vite.cjs +781 -300
  24. package/dist/vite.js +3 -2
  25. package/dist/webpack.cjs +781 -300
  26. package/dist/webpack.js +3 -2
  27. package/package.json +1 -4
  28. package/src/caddy/caddyfile.ts +1 -0
  29. package/src/caddy/index.ts +183 -110
  30. package/src/caddy/privileged.ts +118 -0
  31. package/src/caddy/utils.ts +0 -43
  32. package/src/index.ts +1 -15
  33. package/src/nuxt.ts +1 -6
  34. package/src/privileged/bootstrap.ts +174 -0
  35. package/src/privileged/client.ts +287 -0
  36. package/src/privileged/entry.ts +45 -0
  37. package/src/privileged/hosts-file.ts +142 -0
  38. package/src/privileged/launch.ts +193 -0
  39. package/src/privileged/ports.ts +45 -0
  40. package/src/privileged/protocol.ts +111 -0
  41. package/src/privileged/server.ts +465 -0
  42. package/src/privileged/session.ts +114 -0
  43. package/src/privileged/validation.ts +38 -0
  44. package/src/privileged/windows-elevation.ts +80 -0
  45. package/src/privileged-helper.ts +109 -0
  46. package/src/utils.ts +0 -28
  47. package/src/host/index.ts +0 -52
package/dist/nuxt.cjs CHANGED
@@ -33,22 +33,22 @@ __export(nuxt_exports, {
33
33
  default: () => nuxt_default
34
34
  });
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
- var import_node_process6 = __toESM(require("process"), 1);
36
+ var import_node_process9 = __toESM(require("process"), 1);
37
37
  var import_kit = require("@nuxt/kit");
38
38
 
39
39
  // src/index.ts
40
- var import_node_process5 = __toESM(require("process"), 1);
40
+ var import_node_process8 = __toESM(require("process"), 1);
41
41
  var import_console_table_printer = require("console-table-printer");
42
42
  var import_picocolors2 = __toESM(require("picocolors"), 1);
43
43
  var import_unplugin = require("unplugin");
44
44
 
45
45
  // src/caddy/index.ts
46
- var import_node_child_process4 = require("child_process");
47
- var import_node_fs3 = require("fs");
46
+ var import_node_child_process3 = require("child_process");
47
+ var import_node_fs4 = require("fs");
48
48
  var import_promises3 = require("fs/promises");
49
- var import_node_os3 = require("os");
50
- var import_node_path3 = require("path");
51
- var import_node_process4 = __toESM(require("process"), 1);
49
+ var import_node_os5 = require("os");
50
+ var import_node_path5 = require("path");
51
+ var import_node_process7 = __toESM(require("process"), 1);
52
52
 
53
53
  // node_modules/.pnpm/alien-signals@2.0.7/node_modules/alien-signals/esm/system.mjs
54
54
  var ReactiveFlags;
@@ -490,33 +490,14 @@ var import_http_proxy_agent = require("http-proxy-agent");
490
490
  var import_https_proxy_agent = require("https-proxy-agent");
491
491
  var lockfile = __toESM(require("proper-lockfile"), 1);
492
492
 
493
- // src/host/index.ts
494
- var import_node_child_process2 = require("child_process");
495
- var import_node_fs = require("fs");
496
- var import_node_process2 = __toESM(require("process"), 1);
497
- var import_node_util = require("util");
498
- var import_hostile = __toESM(require("hostile"), 1);
499
-
500
493
  // src/utils.ts
501
- var import_node_child_process = require("child_process");
502
- var import_promises = require("fs/promises");
503
494
  var import_node_os = require("os");
504
- var import_node_path = __toESM(require("path"), 1);
505
- var import_node_process = __toESM(require("process"), 1);
506
495
  var import_consola = require("consola");
507
496
  var import_picocolors = __toESM(require("picocolors"), 1);
508
497
  var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
509
498
  var consola = (0, import_consola.createConsola)({
510
499
  level: 3
511
500
  }).withTag("reverse-proxy");
512
- async function chmodRecursive(_path, mode) {
513
- await (0, import_promises.chmod)(_path, mode);
514
- if ((await (0, import_promises.stat)(_path)).isDirectory()) {
515
- const children = await (0, import_promises.readdir)(_path);
516
- for (const child of children)
517
- await chmodRecursive(import_node_path.default.join(_path, child), mode);
518
- }
519
- }
520
501
  function once(fn) {
521
502
  let called = false;
522
503
  return (...args2) => {
@@ -526,18 +507,6 @@ function once(fn) {
526
507
  return fn(...args2);
527
508
  };
528
509
  }
529
- function isAdmin() {
530
- if (import_node_process.default.platform === "win32") {
531
- try {
532
- (0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
533
- return true;
534
- } catch {
535
- return false;
536
- }
537
- } else {
538
- return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
539
- }
540
- }
541
510
  function getIpv4List() {
542
511
  const interfaces = (0, import_node_os.networkInterfaces)();
543
512
  return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
@@ -552,44 +521,6 @@ async function generateQrcode(input) {
552
521
  });
553
522
  }
554
523
 
555
- // src/host/index.ts
556
- var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
557
- var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
558
- function getPathOfSystemHostsPath() {
559
- return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
560
- }
561
- async function syncHost() {
562
- return new Promise((resolve2, _reject) => {
563
- (0, import_node_child_process2.exec)(
564
- import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
565
- (error, _stdout, _stderr) => {
566
- if (error) {
567
- consola.error(`exec error: ${error}`);
568
- return resolve2(false);
569
- }
570
- return resolve2(true);
571
- }
572
- );
573
- });
574
- }
575
- async function addHost(ip2, host) {
576
- if (import_node_process2.default.platform !== "win32")
577
- (0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
578
- await _setHost("127.0.0.1", "localhost");
579
- await _setHost(ip2, host);
580
- if (ip2 === "localhost")
581
- await _setHost("127.0.0.1", host);
582
- return await syncHost();
583
- }
584
- async function removeHost(ip2, host) {
585
- if (import_node_process2.default.platform !== "win32")
586
- (0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
587
- await _removeHost(ip2, host);
588
- if (ip2 === "localhost")
589
- await _removeHost("127.0.0.1", host);
590
- return await syncHost();
591
- }
592
-
593
524
  // node_modules/.pnpm/@ark+util@0.46.0/node_modules/@ark/util/out/arrays.js
594
525
  var liftArray = (data) => Array.isArray(data) ? data : [data];
595
526
  var spliterate = (arr, predicate) => {
@@ -1217,29 +1148,29 @@ var timeWithUnnecessarySeconds = /:\d\d:00$/;
1217
1148
  var pad = (value2, length) => String(value2).padStart(length, "0");
1218
1149
 
1219
1150
  // node_modules/.pnpm/@ark+util@0.46.0/node_modules/@ark/util/out/path.js
1220
- var appendStringifiedKey = (path2, prop, ...[opts]) => {
1151
+ var appendStringifiedKey = (path, prop, ...[opts]) => {
1221
1152
  const stringifySymbol = (opts == null ? void 0 : opts.stringifySymbol) ?? printable;
1222
- let propAccessChain = path2;
1153
+ let propAccessChain = path;
1223
1154
  switch (typeof prop) {
1224
1155
  case "string":
1225
- propAccessChain = isDotAccessible(prop) ? path2 === "" ? prop : `${path2}.${prop}` : `${path2}[${JSON.stringify(prop)}]`;
1156
+ propAccessChain = isDotAccessible(prop) ? path === "" ? prop : `${path}.${prop}` : `${path}[${JSON.stringify(prop)}]`;
1226
1157
  break;
1227
1158
  case "number":
1228
- propAccessChain = `${path2}[${prop}]`;
1159
+ propAccessChain = `${path}[${prop}]`;
1229
1160
  break;
1230
1161
  case "symbol":
1231
- propAccessChain = `${path2}[${stringifySymbol(prop)}]`;
1162
+ propAccessChain = `${path}[${stringifySymbol(prop)}]`;
1232
1163
  break;
1233
1164
  default:
1234
1165
  if (opts == null ? void 0 : opts.stringifyNonKey)
1235
- propAccessChain = `${path2}[${opts.stringifyNonKey(prop)}]`;
1166
+ propAccessChain = `${path}[${opts.stringifyNonKey(prop)}]`;
1236
1167
  else {
1237
1168
  throwParseError(`${printable(prop)} must be a PropertyKey or stringifyNonKey must be passed to options`);
1238
1169
  }
1239
1170
  }
1240
1171
  return propAccessChain;
1241
1172
  };
1242
- var stringifyPath = (path2, ...opts) => path2.reduce((s, k) => appendStringifiedKey(s, k, ...opts), "");
1173
+ var stringifyPath = (path, ...opts) => path.reduce((s, k) => appendStringifiedKey(s, k, ...opts), "");
1243
1174
  var ReadonlyPath = class extends ReadonlyArray {
1244
1175
  // alternate strategy for caching since the base object is frozen
1245
1176
  cache = {};
@@ -1266,8 +1197,8 @@ var ReadonlyPath = class extends ReadonlyArray {
1266
1197
  return this.cache.stringifyAncestors;
1267
1198
  let propString = "";
1268
1199
  const result = [propString];
1269
- for (const path2 of this) {
1270
- propString = appendStringifiedKey(propString, path2);
1200
+ for (const path of this) {
1201
+ propString = appendStringifiedKey(propString, path);
1271
1202
  result.push(propString);
1272
1203
  }
1273
1204
  return this.cache.stringifyAncestors = result;
@@ -1860,15 +1791,15 @@ var ArkErrors = class _ArkErrors extends ReadonlyArray {
1860
1791
  /**
1861
1792
  * @internal
1862
1793
  */
1863
- affectsPath(path2) {
1794
+ affectsPath(path) {
1864
1795
  if (this.length === 0)
1865
1796
  return false;
1866
1797
  return (
1867
1798
  // this would occur if there is an existing error at a prefix of path
1868
1799
  // e.g. the path is ["foo", "bar"] and there is an error at ["foo"]
1869
- path2.stringifyAncestors().some((s) => s in this.byPath) || // this would occur if there is an existing error at a suffix of path
1800
+ path.stringifyAncestors().some((s) => s in this.byPath) || // this would occur if there is an existing error at a suffix of path
1870
1801
  // e.g. the path is ["foo"] and there is an error at ["foo", "bar"]
1871
- path2.stringify() in this.byAncestorPath
1802
+ path.stringify() in this.byAncestorPath
1872
1803
  );
1873
1804
  }
1874
1805
  /**
@@ -2075,22 +2006,22 @@ var Traversal = class {
2075
2006
  while (this.queuedMorphs.length) {
2076
2007
  const queuedMorphs = this.queuedMorphs;
2077
2008
  this.queuedMorphs = [];
2078
- for (const { path: path2, morphs } of queuedMorphs) {
2079
- if (this.errors.affectsPath(path2))
2009
+ for (const { path, morphs } of queuedMorphs) {
2010
+ if (this.errors.affectsPath(path))
2080
2011
  continue;
2081
- this.applyMorphsAtPath(path2, morphs);
2012
+ this.applyMorphsAtPath(path, morphs);
2082
2013
  }
2083
2014
  }
2084
2015
  }
2085
- applyMorphsAtPath(path2, morphs) {
2086
- const key = path2.at(-1);
2016
+ applyMorphsAtPath(path, morphs) {
2017
+ const key = path.at(-1);
2087
2018
  let parent;
2088
2019
  if (key !== void 0) {
2089
2020
  parent = this.root;
2090
- for (let pathIndex = 0; pathIndex < path2.length - 1; pathIndex++)
2091
- parent = parent[path2[pathIndex]];
2021
+ for (let pathIndex = 0; pathIndex < path.length - 1; pathIndex++)
2022
+ parent = parent[path[pathIndex]];
2092
2023
  }
2093
- this.path = [...path2];
2024
+ this.path = [...path];
2094
2025
  for (const morph of morphs) {
2095
2026
  const morphIsNode = isNode(morph);
2096
2027
  const result = morph(parent === void 0 ? this.root : parent[key], this);
@@ -2460,15 +2391,15 @@ var NodeSelector = {
2460
2391
  normalize: (selector) => typeof selector === "function" ? { boundary: "references", method: "filter", where: selector } : typeof selector === "string" ? isKeyOf(selector, NodeSelector.applyBoundary) ? { method: "filter", boundary: selector } : { boundary: "references", method: "filter", kind: selector } : { boundary: "references", method: "filter", ...selector }
2461
2392
  };
2462
2393
  var writeSelectAssertionMessage = (from, selector) => `${from} had no references matching ${printable(selector)}.`;
2463
- var typePathToPropString = (path2) => stringifyPath(path2, {
2394
+ var typePathToPropString = (path) => stringifyPath(path, {
2464
2395
  stringifyNonKey: (node2) => node2.expression
2465
2396
  });
2466
2397
  var referenceMatcher = /"(\$ark\.[^"]+)"/g;
2467
2398
  var compileMeta = (metaJson) => JSON.stringify(metaJson).replaceAll(referenceMatcher, "$1");
2468
- var flatRef = (path2, node2) => ({
2469
- path: path2,
2399
+ var flatRef = (path, node2) => ({
2400
+ path,
2470
2401
  node: node2,
2471
- propString: typePathToPropString(path2)
2402
+ propString: typePathToPropString(path)
2472
2403
  });
2473
2404
  var flatRefsAreEqual = (l, r) => l.propString === r.propString && l.node.equals(r.node);
2474
2405
  var appendUniqueFlatRefs = (existing, refs) => appendUnique(existing, refs, {
@@ -2504,12 +2435,12 @@ var Disjoint = class _Disjoint extends Array {
2504
2435
  }
2505
2436
  describeReasons() {
2506
2437
  if (this.length === 1) {
2507
- const { path: path2, l, r } = this[0];
2508
- const pathString = stringifyPath(path2);
2438
+ const { path, l, r } = this[0];
2439
+ const pathString = stringifyPath(path);
2509
2440
  return writeUnsatisfiableExpressionError(`Intersection${pathString && ` at ${pathString}`} of ${describeReasons(l, r)}`);
2510
2441
  }
2511
2442
  return `The following intersections result in unsatisfiable types:
2512
- \u2022 ${this.map(({ path: path2, l, r }) => `${path2}: ${describeReasons(l, r)}`).join("\n\u2022 ")}`;
2443
+ \u2022 ${this.map(({ path, l, r }) => `${path}: ${describeReasons(l, r)}`).join("\n\u2022 ")}`;
2513
2444
  }
2514
2445
  throw() {
2515
2446
  return throwParseError(this.describeReasons());
@@ -3869,10 +3800,10 @@ var BaseRoot = class extends BaseNode {
3869
3800
  });
3870
3801
  });
3871
3802
  }
3872
- get(...path2) {
3873
- if (path2[0] === void 0)
3803
+ get(...path) {
3804
+ if (path[0] === void 0)
3874
3805
  return this;
3875
- return this.$.schema(this.applyStructuralOperation("get", path2));
3806
+ return this.$.schema(this.applyStructuralOperation("get", path));
3876
3807
  }
3877
3808
  extract(r) {
3878
3809
  const rNode = this.$.parseDefinition(r);
@@ -4807,13 +4738,13 @@ var implementation17 = implementNode({
4807
4738
  description: (node2) => node2.distribute((branch) => branch.description, describeBranches),
4808
4739
  expected: (ctx) => {
4809
4740
  const byPath = groupBy(ctx.errors, "propString");
4810
- const pathDescriptions = Object.entries(byPath).map(([path2, errors]) => {
4741
+ const pathDescriptions = Object.entries(byPath).map(([path, errors]) => {
4811
4742
  const branchesAtPath = [];
4812
4743
  for (const errorAtPath of errors)
4813
4744
  appendUnique(branchesAtPath, errorAtPath.expected);
4814
4745
  const expected = describeBranches(branchesAtPath);
4815
4746
  const actual = errors.every((e) => e.actual === errors[0].actual) ? errors[0].actual : printable(errors[0].data);
4816
- return `${path2 && `${path2} `}must be ${expected}${actual && ` (was ${actual})`}`;
4747
+ return `${path && `${path} `}must be ${expected}${actual && ` (was ${actual})`}`;
4817
4748
  });
4818
4749
  return describeBranches(pathDescriptions);
4819
4750
  },
@@ -5177,10 +5108,10 @@ var orderCandidates = (candidates, originalBranches) => {
5177
5108
  });
5178
5109
  return viableCandidates;
5179
5110
  };
5180
- var discriminantCaseToNode = (caseDiscriminant, path2, $) => {
5111
+ var discriminantCaseToNode = (caseDiscriminant, path, $) => {
5181
5112
  let node2 = caseDiscriminant === "undefined" ? $.node("unit", { unit: void 0 }) : caseDiscriminant === "null" ? $.node("unit", { unit: null }) : caseDiscriminant === "boolean" ? $.units([true, false]) : caseDiscriminant;
5182
- for (let i = path2.length - 1; i >= 0; i--) {
5183
- const key = path2[i];
5113
+ for (let i = path.length - 1; i >= 0; i--) {
5114
+ const key = path[i];
5184
5115
  node2 = $.node("intersection", typeof key === "number" ? {
5185
5116
  proto: "Array",
5186
5117
  // create unknown for preceding elements (could be optimized with safe imports)
@@ -5192,7 +5123,7 @@ var discriminantCaseToNode = (caseDiscriminant, path2, $) => {
5192
5123
  }
5193
5124
  return node2;
5194
5125
  };
5195
- var optionallyChainPropString = (path2) => path2.reduce((acc, k) => acc + compileLiteralPropAccess(k, true), "data");
5126
+ var optionallyChainPropString = (path) => path.reduce((acc, k) => acc + compileLiteralPropAccess(k, true), "data");
5196
5127
  var serializedTypeOfDescriptions = registeredReference(jsTypeOfDescriptions);
5197
5128
  var serializedPrintable = registeredReference(printable);
5198
5129
  var Union = {
@@ -6150,7 +6081,7 @@ var StructureNode = class extends BaseConstraint {
6150
6081
  return throwParseError(writeInvalidKeysMessage(this.expression, invalidKeys));
6151
6082
  }
6152
6083
  }
6153
- get(indexer, ...path2) {
6084
+ get(indexer, ...path) {
6154
6085
  var _a4;
6155
6086
  let value2;
6156
6087
  let required = false;
@@ -6187,7 +6118,7 @@ var StructureNode = class extends BaseConstraint {
6187
6118
  }
6188
6119
  return throwParseError(writeInvalidKeysMessage(this.expression, [key]));
6189
6120
  }
6190
- const result = value2.get(...path2);
6121
+ const result = value2.get(...path);
6191
6122
  return required ? result : result.or($ark.intrinsic.undefined);
6192
6123
  }
6193
6124
  pick(...keys) {
@@ -8913,7 +8844,7 @@ function isIterator(val) {
8913
8844
  function escapeRegex(str) {
8914
8845
  return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
8915
8846
  }
8916
- function promisify2(fn) {
8847
+ function promisify(fn) {
8917
8848
  return function(...args2) {
8918
8849
  return new Promise((resolve2, reject2) => {
8919
8850
  fn(...args2, (err, result) => {
@@ -10249,8 +10180,8 @@ function requireResolve(file) {
10249
10180
  const require2 = (0, import_module3.createRequire)(process.cwd() + "/");
10250
10181
  return require2.resolve(file);
10251
10182
  }
10252
- var statAsync = promisify2(import_fs.stat);
10253
- var readFileAsync = promisify2(import_fs.readFile);
10183
+ var statAsync = promisify(import_fs.stat);
10184
+ var readFileAsync = promisify(import_fs.readFile);
10254
10185
  function exists(filepath) {
10255
10186
  return __awaiter(this, void 0, void 0, function* () {
10256
10187
  try {
@@ -11492,10 +11423,10 @@ var Loader = class {
11492
11423
  yield filepath;
11493
11424
  }
11494
11425
  }
11495
- dirname(path2) {
11426
+ dirname(path) {
11496
11427
  const fs2 = this.options.fs;
11497
11428
  assert(fs2.dirname, "`fs.dirname` is required for relative reference");
11498
- return fs2.dirname(path2);
11429
+ return fs2.dirname(path);
11499
11430
  }
11500
11431
  lookupError(file, roots) {
11501
11432
  const err = new Error("ENOENT");
@@ -13457,6 +13388,7 @@ function validateTemplateContext(ctx) {
13457
13388
  var caddyTemplate = `{
13458
13389
  debug
13459
13390
  auto_https disable_redirects ignore_loaded_certs
13391
+ skip_install_trust
13460
13392
  }
13461
13393
 
13462
13394
  :7601 {
@@ -13537,27 +13469,27 @@ async function genCaddyfile(ctx) {
13537
13469
  }
13538
13470
 
13539
13471
  // src/caddy/config.ts
13540
- var import_node_fs2 = require("fs");
13541
- var import_promises2 = require("fs/promises");
13472
+ var import_node_fs = require("fs");
13473
+ var import_promises = require("fs/promises");
13542
13474
 
13543
13475
  // src/caddy/constants.ts
13544
13476
  var import_node_os2 = __toESM(require("os"), 1);
13545
- var import_node_path2 = require("path");
13546
- var import_node_process3 = __toESM(require("process"), 1);
13477
+ var import_node_path = require("path");
13478
+ var import_node_process = __toESM(require("process"), 1);
13547
13479
  var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
13548
13480
  import_dotenv_flow.default.config({
13549
13481
  silent: true
13550
13482
  });
13551
- function resolvePath(path2) {
13552
- if (path2.startsWith("~"))
13553
- return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
13554
- return path2;
13555
- }
13556
- var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
13557
- var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
13558
- var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
13559
- var caddyConfigPath = (0, import_node_path2.join)(TEMP_DIR, ".CADDYFILE.config.json");
13560
- var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
13483
+ function resolvePath(path) {
13484
+ if (path.startsWith("~"))
13485
+ return (0, import_node_path.join)(import_node_os2.default.homedir() || "", path.slice(1));
13486
+ return path;
13487
+ }
13488
+ var TEMP_DIR = resolvePath(import_node_process.default.env.UHRP_CADDY_PATH || import_node_process.default.env.TEMP || import_node_process.default.env.TMPDIR || "/tmp");
13489
+ var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process.default.platform === "win32" ? ".exe" : ""}`);
13490
+ var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
13491
+ var caddyConfigPath = (0, import_node_path.join)(TEMP_DIR, ".CADDYFILE.config.json");
13492
+ var caddyLockFilePath = (0, import_node_path.join)(TEMP_DIR, "caddylock");
13561
13493
  var supportList = [
13562
13494
  {
13563
13495
  platform: "dragonfly",
@@ -13680,19 +13612,19 @@ function useCaddyConfig() {
13680
13612
  }
13681
13613
  });
13682
13614
  function setConfigContent() {
13683
- if (!(0, import_node_fs2.existsSync)(caddyConfigPath)) {
13684
- (0, import_node_fs2.writeFileSync)(caddyConfigPath, "{}");
13615
+ if (!(0, import_node_fs.existsSync)(caddyConfigPath)) {
13616
+ (0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
13685
13617
  }
13686
13618
  try {
13687
- configContentRef((0, import_node_fs2.readFileSync)(caddyConfigPath, "utf-8"));
13619
+ configContentRef((0, import_node_fs.readFileSync)(caddyConfigPath, "utf-8"));
13688
13620
  } catch {
13689
13621
  configContentRef("");
13690
13622
  }
13691
13623
  }
13692
- if (!(0, import_node_fs2.existsSync)(caddyConfigPath)) {
13693
- (0, import_node_fs2.writeFileSync)(caddyConfigPath, "{}");
13624
+ if (!(0, import_node_fs.existsSync)(caddyConfigPath)) {
13625
+ (0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
13694
13626
  }
13695
- const watchCaddyConfig = (0, import_node_fs2.watch)(caddyConfigPath, () => {
13627
+ const watchCaddyConfig = (0, import_node_fs.watch)(caddyConfigPath, () => {
13696
13628
  setConfigContent();
13697
13629
  });
13698
13630
  function writeCaddyConfig(_proxies) {
@@ -13708,10 +13640,10 @@ function useCaddyConfig() {
13708
13640
  });
13709
13641
  const content = JSON.stringify(proxies, null, 2);
13710
13642
  configContentRef(content);
13711
- return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
13643
+ return (0, import_node_fs.writeFileSync)(caddyConfigPath, content);
13712
13644
  }
13713
13645
  async function cleanUp() {
13714
- await (0, import_promises2.unlink)(caddyConfigPath).catch(() => {
13646
+ await (0, import_promises.unlink)(caddyConfigPath).catch(() => {
13715
13647
  });
13716
13648
  configContentRef("{}");
13717
13649
  watchCaddyConfig.close();
@@ -13733,6 +13665,552 @@ function isCaddyReloadCancellation(line) {
13733
13665
  }
13734
13666
  }
13735
13667
 
13668
+ // src/caddy/privileged.ts
13669
+ var import_node_buffer2 = require("buffer");
13670
+ var import_node_events = require("events");
13671
+ var import_node_path4 = require("path");
13672
+ var import_node_process6 = __toESM(require("process"), 1);
13673
+ var import_node_url = require("url");
13674
+
13675
+ // src/privileged/entry.ts
13676
+ var import_node_fs2 = require("fs");
13677
+ var import_node_path2 = require("path");
13678
+ var import_node_process2 = __toESM(require("process"), 1);
13679
+ function resolveHelperEntry(options) {
13680
+ const { moduleDir, nodeBin = import_node_process2.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
13681
+ for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
13682
+ const candidate = (0, import_node_path2.join)(moduleDir, name);
13683
+ if (exists2(candidate))
13684
+ return { entry: nodeBin, args: [candidate] };
13685
+ }
13686
+ const source = (0, import_node_path2.join)(moduleDir, "privileged-helper.ts");
13687
+ const tsxCli = (0, import_node_path2.join)(moduleDir, "../node_modules/tsx/dist/cli.mjs");
13688
+ if (exists2(source) && exists2(tsxCli))
13689
+ return { entry: nodeBin, args: [tsxCli, source] };
13690
+ throw new Error(`privileged helper entry not found in ${moduleDir}. Build the package first.`);
13691
+ }
13692
+
13693
+ // src/privileged/session.ts
13694
+ var import_node_buffer = require("buffer");
13695
+ var import_node_fs3 = require("fs");
13696
+ var import_promises2 = require("fs/promises");
13697
+ var import_node_os4 = require("os");
13698
+ var import_node_path3 = require("path");
13699
+
13700
+ // src/privileged/launch.ts
13701
+ var import_node_child_process2 = require("child_process");
13702
+ var import_node_crypto = require("crypto");
13703
+ var import_node_os3 = require("os");
13704
+ var import_node_process5 = __toESM(require("process"), 1);
13705
+
13706
+ // src/privileged/client.ts
13707
+ var import_node_net = require("net");
13708
+ var import_node_process3 = __toESM(require("process"), 1);
13709
+
13710
+ // src/privileged/protocol.ts
13711
+ function serializeMessage(message) {
13712
+ return `${JSON.stringify(message)}
13713
+ `;
13714
+ }
13715
+ function splitLines(buffer, chunk) {
13716
+ const parts = (buffer + chunk).split("\n");
13717
+ const rest = parts.pop() ?? "";
13718
+ return { lines: parts.filter((line) => line.trim() !== ""), rest };
13719
+ }
13720
+ function isRecord(value2) {
13721
+ return typeof value2 === "object" && value2 !== null;
13722
+ }
13723
+ function decodeMessage(line) {
13724
+ let parsed2;
13725
+ try {
13726
+ parsed2 = JSON.parse(line);
13727
+ } catch (error) {
13728
+ return { ok: false, error: `invalid JSON: ${error.message}` };
13729
+ }
13730
+ if (!isRecord(parsed2))
13731
+ return { ok: false, error: "message must be an object" };
13732
+ if (parsed2.type === "event") {
13733
+ if (typeof parsed2.kind !== "string")
13734
+ return { ok: false, error: "event.kind must be a string" };
13735
+ return { ok: true, message: parsed2 };
13736
+ }
13737
+ if (typeof parsed2.id !== "number")
13738
+ return { ok: false, error: "response.id must be a number" };
13739
+ if (parsed2.ok === true)
13740
+ return { ok: true, message: { id: parsed2.id, ok: true, result: parsed2.result } };
13741
+ if (parsed2.ok === false) {
13742
+ const error = isRecord(parsed2.error) ? parsed2.error : {};
13743
+ return {
13744
+ ok: true,
13745
+ message: {
13746
+ id: parsed2.id,
13747
+ ok: false,
13748
+ error: {
13749
+ message: typeof error.message === "string" ? error.message : "helper request failed",
13750
+ code: typeof error.code === "string" ? error.code : void 0
13751
+ }
13752
+ }
13753
+ };
13754
+ }
13755
+ return { ok: false, error: "response.ok must be a boolean" };
13756
+ }
13757
+
13758
+ // src/privileged/client.ts
13759
+ var FORWARDED_ENV_KEYS = [
13760
+ "HOME",
13761
+ "USER",
13762
+ "LOGNAME",
13763
+ "TMPDIR",
13764
+ "HTTP_PROXY",
13765
+ "HTTPS_PROXY",
13766
+ "http_proxy",
13767
+ "https_proxy",
13768
+ "NO_PROXY",
13769
+ "no_proxy"
13770
+ ];
13771
+ function collectForwardedEnv(source = import_node_process3.default.env) {
13772
+ const result = {};
13773
+ for (const key of FORWARDED_ENV_KEYS) {
13774
+ const value2 = source[key];
13775
+ if (typeof value2 === "string" && value2 !== "")
13776
+ result[key] = value2;
13777
+ }
13778
+ return result;
13779
+ }
13780
+ var HelperConnectionError = class extends Error {
13781
+ constructor(message) {
13782
+ super(message);
13783
+ this.name = "HelperConnectionError";
13784
+ }
13785
+ };
13786
+ function openSocket(socketPath) {
13787
+ return new Promise((resolve2, reject2) => {
13788
+ const socket = (0, import_node_net.connect)(socketPath);
13789
+ function onConnect() {
13790
+ socket.removeListener("error", onError);
13791
+ resolve2(socket);
13792
+ }
13793
+ function onError(error) {
13794
+ socket.removeListener("connect", onConnect);
13795
+ reject2(error);
13796
+ }
13797
+ socket.once("error", onError);
13798
+ socket.once("connect", onConnect);
13799
+ });
13800
+ }
13801
+ async function connectClient(options) {
13802
+ const {
13803
+ socketPath,
13804
+ token,
13805
+ timeoutMs = 12e4,
13806
+ retryIntervalMs = 100,
13807
+ callTimeoutMs = 3e4
13808
+ } = options;
13809
+ const deadline = Date.now() + timeoutMs;
13810
+ let lastError;
13811
+ while (Date.now() < deadline) {
13812
+ try {
13813
+ return await handshake(socketPath, token, callTimeoutMs);
13814
+ } catch (error) {
13815
+ lastError = error;
13816
+ const code = lastError.code;
13817
+ if (code === "EACCES" || lastError instanceof HelperConnectionError)
13818
+ throw lastError;
13819
+ await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
13820
+ }
13821
+ }
13822
+ throw new HelperConnectionError(
13823
+ `privileged helper is not reachable at ${socketPath}: ${(lastError == null ? void 0 : lastError.message) ?? "timed out"}`
13824
+ );
13825
+ }
13826
+ function handshake(socketPath, token, callTimeoutMs) {
13827
+ return new Promise((resolve2, reject2) => {
13828
+ void openSocket(socketPath).then((socket) => {
13829
+ let buffer = "";
13830
+ let settled = false;
13831
+ const fail = (error) => {
13832
+ if (settled)
13833
+ return;
13834
+ settled = true;
13835
+ socket.destroy();
13836
+ reject2(error);
13837
+ };
13838
+ const onData = (chunk) => {
13839
+ if (settled)
13840
+ return;
13841
+ const split2 = splitLines(buffer, chunk.toString("utf8"));
13842
+ buffer = split2.rest;
13843
+ const line = split2.lines[0];
13844
+ if (line === void 0)
13845
+ return;
13846
+ let hello;
13847
+ try {
13848
+ hello = JSON.parse(line);
13849
+ } catch (error) {
13850
+ return fail(new HelperConnectionError(`invalid handshake reply: ${error.message}`));
13851
+ }
13852
+ if (hello.type !== "handshake")
13853
+ return fail(new HelperConnectionError("helper did not answer the handshake"));
13854
+ if (!hello.ok)
13855
+ return fail(new HelperConnectionError(hello.reason ?? "helper rejected the handshake"));
13856
+ settled = true;
13857
+ socket.removeListener("data", onData);
13858
+ socket.removeListener("error", onError);
13859
+ const remaining = split2.lines.slice(1);
13860
+ resolve2(createClient(socket, [split2.rest, ...remaining].filter(Boolean).join("\n"), callTimeoutMs));
13861
+ };
13862
+ function onError(error) {
13863
+ fail(error);
13864
+ }
13865
+ socket.on("data", onData);
13866
+ socket.on("error", onError);
13867
+ const greeting = { type: "handshake", token };
13868
+ socket.write(serializeMessage(greeting));
13869
+ }, reject2);
13870
+ });
13871
+ }
13872
+ function createClient(socket, initialBuffer, callTimeoutMs) {
13873
+ let buffer = initialBuffer;
13874
+ let connected = true;
13875
+ let nextId = 1;
13876
+ const pending = /* @__PURE__ */ new Map();
13877
+ const listeners = /* @__PURE__ */ new Set();
13878
+ socket.on("data", (chunk) => {
13879
+ const split2 = splitLines(buffer, chunk.toString("utf8"));
13880
+ buffer = split2.rest;
13881
+ for (const line of split2.lines) {
13882
+ const decoded = decodeMessage(line);
13883
+ if (!decoded.ok)
13884
+ continue;
13885
+ const message = decoded.message;
13886
+ if (!("id" in message)) {
13887
+ for (const listener of listeners)
13888
+ listener(message);
13889
+ continue;
13890
+ }
13891
+ const entry = pending.get(message.id);
13892
+ if (!entry)
13893
+ continue;
13894
+ pending.delete(message.id);
13895
+ clearTimeout(entry.timer);
13896
+ if (message.ok)
13897
+ entry.resolve(message.result);
13898
+ else
13899
+ entry.reject(new Error(message.error.message));
13900
+ }
13901
+ });
13902
+ const disconnect = () => {
13903
+ if (!connected)
13904
+ return;
13905
+ connected = false;
13906
+ for (const [id, entry] of pending) {
13907
+ clearTimeout(entry.timer);
13908
+ pending.delete(id);
13909
+ entry.reject(new HelperConnectionError("privileged helper connection closed"));
13910
+ }
13911
+ };
13912
+ socket.on("close", disconnect);
13913
+ socket.on("error", disconnect);
13914
+ function call(method, params) {
13915
+ if (!connected)
13916
+ return Promise.reject(new HelperConnectionError("privileged helper is not connected"));
13917
+ const id = nextId++;
13918
+ const request = { id, method, params };
13919
+ return new Promise((resolve2, reject2) => {
13920
+ const timer = setTimeout(() => {
13921
+ pending.delete(id);
13922
+ reject2(new HelperConnectionError(`privileged helper did not answer "${method}" in time`));
13923
+ }, callTimeoutMs);
13924
+ pending.set(id, { resolve: resolve2, reject: reject2, timer });
13925
+ socket.write(serializeMessage(request));
13926
+ });
13927
+ }
13928
+ return {
13929
+ get connected() {
13930
+ return connected;
13931
+ },
13932
+ call,
13933
+ onEvent(listener) {
13934
+ listeners.add(listener);
13935
+ return () => {
13936
+ listeners.delete(listener);
13937
+ };
13938
+ },
13939
+ async close() {
13940
+ disconnect();
13941
+ socket.destroy();
13942
+ }
13943
+ };
13944
+ }
13945
+
13946
+ // src/privileged/windows-elevation.ts
13947
+ var import_node_child_process = require("child_process");
13948
+ var import_node_process4 = __toESM(require("process"), 1);
13949
+ function quotePowerShell(value2) {
13950
+ return `'${value2.replace(/'/g, "''")}'`;
13951
+ }
13952
+ function buildElevationCommand(options) {
13953
+ const argumentList = options.args.map(quotePowerShell).join(",");
13954
+ const parts = [
13955
+ "Start-Process",
13956
+ "-FilePath",
13957
+ quotePowerShell(options.file)
13958
+ ];
13959
+ if (argumentList)
13960
+ parts.push("-ArgumentList", argumentList);
13961
+ if (options.cwd)
13962
+ parts.push("-WorkingDirectory", quotePowerShell(options.cwd));
13963
+ parts.push("-Verb", "RunAs");
13964
+ parts.push("-WindowStyle", "Hidden");
13965
+ return parts.join(" ");
13966
+ }
13967
+ function spawnElevatedOnWindows(options) {
13968
+ return new Promise((resolve2, reject2) => {
13969
+ const script = buildElevationCommand(options);
13970
+ const child = (0, import_node_child_process.spawn)(
13971
+ "powershell.exe",
13972
+ ["-NoProfile", "-NonInteractive", "-Command", script],
13973
+ { stdio: "ignore", windowsHide: true }
13974
+ );
13975
+ child.once("error", reject2);
13976
+ child.once("exit", (code) => {
13977
+ if (code === 0)
13978
+ return resolve2(child);
13979
+ reject2(new Error(
13980
+ `administrator permission was not granted (PowerShell exited with ${code}). Accept the UAC prompt to let the plugin edit the hosts file and bind ports 80/443.`
13981
+ ));
13982
+ });
13983
+ });
13984
+ }
13985
+
13986
+ // src/privileged/launch.ts
13987
+ function createHelperToken() {
13988
+ return (0, import_node_crypto.randomBytes)(24).toString("hex");
13989
+ }
13990
+ function authenticateSudo(sudoCommand = "sudo") {
13991
+ if ((0, import_node_os3.platform)() === "win32")
13992
+ return { ok: true };
13993
+ if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
13994
+ return { ok: true };
13995
+ if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-v"], { stdio: "inherit" }).status === 0)
13996
+ return { ok: true };
13997
+ return {
13998
+ ok: false,
13999
+ message: "administrator permission is required to edit the hosts file and bind ports 80/443"
14000
+ };
14001
+ }
14002
+ async function startPrivilegedHelper(options) {
14003
+ var _a4, _b3;
14004
+ const {
14005
+ socketPath,
14006
+ token,
14007
+ helperEntry,
14008
+ helperArgs = [],
14009
+ sudoCommand = "sudo",
14010
+ skipAuth = false,
14011
+ direct = false,
14012
+ env: env2 = import_node_process5.default.env,
14013
+ log,
14014
+ connectTimeoutMs = 12e4
14015
+ } = options;
14016
+ if (!skipAuth && !direct) {
14017
+ const auth = authenticateSudo(sudoCommand);
14018
+ if (!auth.ok)
14019
+ throw new Error(auth.message);
14020
+ }
14021
+ const forwarded = collectForwardedEnv(env2);
14022
+ const forwardedArgs = Object.entries(forwarded).map(([key, value2]) => `${key}=${value2}`);
14023
+ const childArgv = [
14024
+ ...helperArgs,
14025
+ "--socket",
14026
+ socketPath,
14027
+ "--token",
14028
+ token,
14029
+ ...typeof import_node_process5.default.getuid === "function" ? ["--owner-uid", String(import_node_process5.default.getuid())] : [],
14030
+ ...typeof import_node_process5.default.getgid === "function" ? ["--owner-gid", String(import_node_process5.default.getgid())] : [],
14031
+ ...options.caddyStoragePath ? ["--caddy-storage", options.caddyStoragePath] : [],
14032
+ "--caddy",
14033
+ options.caddyBin,
14034
+ "--caddy-config",
14035
+ options.caddyConfigPath
14036
+ ];
14037
+ let child;
14038
+ if (!direct && (0, import_node_os3.platform)() === "win32") {
14039
+ await spawnElevatedOnWindows({ file: helperEntry, args: childArgv, cwd: import_node_process5.default.cwd() });
14040
+ } else {
14041
+ const command = direct ? helperEntry : sudoCommand;
14042
+ const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
14043
+ child = (0, import_node_child_process2.spawn)(command, spawnArgs, {
14044
+ stdio: ["ignore", "pipe", "pipe"]
14045
+ });
14046
+ (_a4 = child.stdout) == null ? void 0 : _a4.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
14047
+ (_b3 = child.stderr) == null ? void 0 : _b3.on("data", (data) => log == null ? void 0 : log(data.toString().trimEnd()));
14048
+ const exited = new Promise((resolve2) => child.once("exit", (code) => resolve2(code)));
14049
+ const earlyExit = await Promise.race([
14050
+ exited,
14051
+ new Promise((resolve2) => setTimeout(() => resolve2(void 0), 500))
14052
+ ]);
14053
+ if (earlyExit !== void 0 && earlyExit !== 0) {
14054
+ throw new Error(
14055
+ `privileged helper exited with code ${earlyExit}. Administrator permission was refused, or sudo is not available.`
14056
+ );
14057
+ }
14058
+ }
14059
+ try {
14060
+ const client = await connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
14061
+ return {
14062
+ client,
14063
+ async close() {
14064
+ await client.close().catch(() => {
14065
+ });
14066
+ child == null ? void 0 : child.unref();
14067
+ }
14068
+ };
14069
+ } catch (error) {
14070
+ try {
14071
+ child == null ? void 0 : child.kill();
14072
+ } catch {
14073
+ }
14074
+ throw error;
14075
+ }
14076
+ }
14077
+ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
14078
+ try {
14079
+ return await connectClient({ socketPath, token, timeoutMs });
14080
+ } catch {
14081
+ return void 0;
14082
+ }
14083
+ }
14084
+
14085
+ // src/privileged/session.ts
14086
+ function tokenPath(runtimeDir) {
14087
+ return (0, import_node_path3.join)(runtimeDir, "helper.token");
14088
+ }
14089
+ function sessionSocketPath(runtimeDir) {
14090
+ if ((0, import_node_os4.platform)() === "win32")
14091
+ return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
14092
+ return (0, import_node_path3.join)(runtimeDir, "helper.sock");
14093
+ }
14094
+ async function openHelperSession(scope2) {
14095
+ const socketPath = sessionSocketPath(scope2.runtimeDir);
14096
+ if ((0, import_node_fs3.existsSync)(socketPath) || (0, import_node_os4.platform)() === "win32") {
14097
+ const token2 = await readToken(scope2.runtimeDir);
14098
+ if (token2) {
14099
+ const reused = await connectExistingHelper(socketPath, token2);
14100
+ if (reused) {
14101
+ return {
14102
+ client: reused,
14103
+ reused: true,
14104
+ close: async () => {
14105
+ await reused.close();
14106
+ }
14107
+ };
14108
+ }
14109
+ }
14110
+ }
14111
+ const token = createHelperToken();
14112
+ const started = await startPrivilegedHelper({
14113
+ socketPath,
14114
+ token,
14115
+ helperEntry: scope2.helperEntry,
14116
+ helperArgs: scope2.helperArgs,
14117
+ sudoCommand: scope2.sudoCommand,
14118
+ skipAuth: scope2.skipAuth,
14119
+ direct: scope2.direct,
14120
+ env: scope2.env,
14121
+ caddyStoragePath: scope2.caddyStoragePath,
14122
+ caddyBin: scope2.caddyBin,
14123
+ caddyConfigPath: scope2.caddyConfigPath,
14124
+ log: scope2.log
14125
+ });
14126
+ await writeToken(scope2.runtimeDir, token);
14127
+ return {
14128
+ client: started.client,
14129
+ reused: false,
14130
+ close: async () => {
14131
+ await started.close();
14132
+ }
14133
+ };
14134
+ }
14135
+ async function readToken(runtimeDir) {
14136
+ try {
14137
+ const content = await (0, import_promises2.readFile)(tokenPath(runtimeDir), "utf8");
14138
+ const token = content.trim();
14139
+ return token === "" ? void 0 : token;
14140
+ } catch {
14141
+ return void 0;
14142
+ }
14143
+ }
14144
+ async function writeToken(runtimeDir, token) {
14145
+ try {
14146
+ await (0, import_promises2.writeFile)(tokenPath(runtimeDir), token, { mode: 384 });
14147
+ } catch {
14148
+ }
14149
+ }
14150
+
14151
+ // src/caddy/privileged.ts
14152
+ var import_meta = {};
14153
+ function resolvePrivilegedEnv() {
14154
+ const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path4.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
14155
+ const resolved = resolveHelperEntry({ moduleDir });
14156
+ return { helperEntry: resolved.entry, helperArgs: resolved.args };
14157
+ }
14158
+ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
14159
+ constructor(client) {
14160
+ super();
14161
+ this.client = client;
14162
+ this.stdout = new import_node_events.EventEmitter();
14163
+ this.stderr = new import_node_events.EventEmitter();
14164
+ this.finished = false;
14165
+ this.unsubscribe = client.onEvent((event) => this.handleEvent(event));
14166
+ }
14167
+ handleEvent(event) {
14168
+ if (event.type !== "event")
14169
+ return;
14170
+ if (event.kind === "caddy.stdout") {
14171
+ this.stdout.emit("data", import_node_buffer2.Buffer.from(event.data));
14172
+ return;
14173
+ }
14174
+ if (event.kind === "caddy.stderr") {
14175
+ this.stderr.emit("data", import_node_buffer2.Buffer.from(event.data));
14176
+ return;
14177
+ }
14178
+ if (event.kind === "caddy.exit") {
14179
+ this.finished = true;
14180
+ this.emit("exit", event.code, event.signal);
14181
+ }
14182
+ }
14183
+ /** Asks the helper to stop Caddy; the helper also stops it on disconnect. */
14184
+ kill() {
14185
+ this.unsubscribe();
14186
+ if (this.finished)
14187
+ return;
14188
+ this.finished = true;
14189
+ void this.client.call("caddy.stop").catch(() => {
14190
+ });
14191
+ }
14192
+ };
14193
+ function caddyStoragePath() {
14194
+ return import_node_process6.default.platform === "win32" ? (0, import_node_path4.join)(import_node_process6.default.env.AppData ?? "", "Caddy") : (0, import_node_path4.join)(import_node_process6.default.env.HOME ?? "", "Library/Application Support/Caddy");
14195
+ }
14196
+ function openPrivilegedSession(runtimeDir, options) {
14197
+ const env2 = resolvePrivilegedEnv();
14198
+ return openHelperSession({
14199
+ runtimeDir,
14200
+ helperEntry: env2.helperEntry,
14201
+ helperArgs: env2.helperArgs,
14202
+ direct: options.direct,
14203
+ // Caddy keeps its PKI under the user's home; the helper runs it as root, so
14204
+ // it must know which tree to hand back afterwards.
14205
+ caddyStoragePath: caddyStoragePath(),
14206
+ // The binary and Caddyfile are fixed here: the privileged helper must never
14207
+ // execute a path supplied over the socket.
14208
+ caddyBin: options.caddyBin,
14209
+ caddyConfigPath: options.caddyConfigPath,
14210
+ log: options.log
14211
+ });
14212
+ }
14213
+
13736
14214
  // src/caddy/tls-health.ts
13737
14215
  var import_node_tls = require("tls");
13738
14216
  function assessTlsCertificate(certificate, hostname, now = Date.now(), verifyHostname = import_node_tls.checkServerIdentity) {
@@ -13815,40 +14293,8 @@ function formatTlsHealthFailure(hostname, result) {
13815
14293
  }
13816
14294
 
13817
14295
  // src/caddy/utils.ts
13818
- var import_node_child_process3 = require("child_process");
13819
- var import_node_net = require("net");
13820
14296
  var import_ora = __toESM(require("ora"), 1);
13821
14297
  var spinner;
13822
- function tryPort(port) {
13823
- return new Promise((resolve2, _reject) => {
13824
- try {
13825
- const server = (0, import_node_net.createServer)().listen(port);
13826
- server.on("listening", () => {
13827
- server.close();
13828
- resolve2(false);
13829
- });
13830
- server.on("error", (err) => {
13831
- if (err.code === "EADDRINUSE")
13832
- resolve2(true);
13833
- server.close();
13834
- });
13835
- } catch {
13836
- resolve2(true);
13837
- }
13838
- });
13839
- }
13840
- async function kill(port) {
13841
- return new Promise((resolve2, reject2) => {
13842
- (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
13843
- if (err) {
13844
- reject2(err);
13845
- } else {
13846
- consola.log(stdout);
13847
- resolve2();
13848
- }
13849
- });
13850
- });
13851
- }
13852
14298
  function getNumber(number2) {
13853
14299
  if (number2 <= 0)
13854
14300
  return "0%";
@@ -13887,26 +14333,26 @@ async function download() {
13887
14333
  if (await testCaddy())
13888
14334
  return caddyPath;
13889
14335
  return new Promise((resolve2, reject2) => {
13890
- if (!(0, import_node_fs3.existsSync)(TEMP_DIR)) {
13891
- (0, import_node_fs3.mkdirSync)(TEMP_DIR, { recursive: true });
13892
- (0, import_node_fs3.chmodSync)(TEMP_DIR, 511);
14336
+ if (!(0, import_node_fs4.existsSync)(TEMP_DIR)) {
14337
+ (0, import_node_fs4.mkdirSync)(TEMP_DIR, { recursive: true });
14338
+ (0, import_node_fs4.chmodSync)(TEMP_DIR, 448);
13893
14339
  }
13894
- const file = (0, import_node_fs3.createWriteStream)(caddyPath);
13895
- let _platform = (0, import_node_os3.platform)().toString();
14340
+ const file = (0, import_node_fs4.createWriteStream)(caddyPath);
14341
+ let _platform = (0, import_node_os5.platform)().toString();
13896
14342
  _platform === "win32" && (_platform = "windows");
13897
- let _arch = import_node_process4.default.arch.toString();
14343
+ let _arch = import_node_process7.default.arch.toString();
13898
14344
  _arch === "x64" && (_arch = "amd64");
13899
14345
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
13900
14346
  if (!support)
13901
14347
  return reject2(new Error("not support"));
13902
14348
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
13903
- (0, import_node_fs3.existsSync)(caddyPath) && (0, import_node_fs3.unlinkSync)(caddyPath);
13904
- const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
13905
- const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
14349
+ (0, import_node_fs4.existsSync)(caddyPath) && (0, import_node_fs4.unlinkSync)(caddyPath);
14350
+ const httpProxy = import_node_process7.default.env.HTTP_PROXY || import_node_process7.default.env.http_proxy;
14351
+ const httpsProxy = import_node_process7.default.env.HTTPS_PROXY || import_node_process7.default.env.https_proxy;
13906
14352
  const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
13907
14353
  const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
13908
14354
  const chmodCaddyOnce = once(() => {
13909
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
14355
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
13910
14356
  });
13911
14357
  import_got_cjs.got.stream(dowmloadLink, {
13912
14358
  agent: {
@@ -13918,9 +14364,9 @@ async function download() {
13918
14364
  chmodCaddyOnce();
13919
14365
  }).pipe(file).on("finish", () => {
13920
14366
  logProgressOver();
13921
- if (import_node_process4.default.platform === "win32")
14367
+ if (import_node_process7.default.platform === "win32")
13922
14368
  return resolve2(caddyPath);
13923
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
14369
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
13924
14370
  resolve2(caddyPath);
13925
14371
  }).on("error", (err) => {
13926
14372
  reject2(err);
@@ -13928,19 +14374,17 @@ async function download() {
13928
14374
  });
13929
14375
  }
13930
14376
  function testCaddy() {
13931
- return new Promise((resolve2, reject2) => {
13932
- if (!(0, import_node_fs3.existsSync)(caddyPath))
13933
- return resolve2(false);
13934
- (0, import_node_fs3.chmodSync)(caddyPath, 511);
13935
- const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
13936
- child.on("close", () => {
14377
+ return new Promise((resolve2) => {
14378
+ if (!(0, import_node_fs4.existsSync)(caddyPath))
13937
14379
  return resolve2(false);
13938
- });
13939
- child.on("error", (err) => {
13940
- return reject2(err);
13941
- });
13942
- child.stdout.on("data", (_data) => {
13943
- return resolve2(true);
14380
+ try {
14381
+ (0, import_node_fs4.chmodSync)(caddyPath, 493);
14382
+ } catch {
14383
+ }
14384
+ (0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
14385
+ if (error && !stdout)
14386
+ return resolve2(false);
14387
+ resolve2(stdout.length > 0);
13944
14388
  });
13945
14389
  });
13946
14390
  }
@@ -13962,25 +14406,48 @@ function splitHostPort(addr) {
13962
14406
  }
13963
14407
  return { host: addr.slice(0, lastColon), port: addr.slice(lastColon + 1) };
13964
14408
  }
14409
+ var defaultDependencies = {
14410
+ openSession: (runtimeDir) => openPrivilegedSession(runtimeDir, {
14411
+ log: (message) => consola.debug(message),
14412
+ // Both paths are fixed here, before any socket traffic: the privileged
14413
+ // helper must never execute something named in a request.
14414
+ caddyBin: caddyPath,
14415
+ caddyConfigPath: caddyFilePath
14416
+ })
14417
+ };
13965
14418
  var CaddyInstant = class {
13966
- constructor() {
14419
+ constructor(deps = {}) {
13967
14420
  this.inited = false;
13968
14421
  this.stoped = false;
13969
14422
  /** has locked when start */
13970
14423
  this.locked = false;
13971
14424
  this._stopEffects = [];
13972
- testCaddy().then(async () => {
13973
- this.inited = true;
13974
- });
14425
+ this.deps = { ...defaultDependencies, ...deps };
13975
14426
  this.locked = this.checkLock();
13976
14427
  }
13977
14428
  checkLock() {
13978
- if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
13979
- (0, import_node_fs3.writeFileSync)(caddyLockFilePath, "");
13980
- return lockfile.checkSync(caddyLockFilePath);
14429
+ if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
14430
+ (0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
14431
+ try {
14432
+ return lockfile.checkSync(caddyLockFilePath);
14433
+ } catch {
14434
+ return false;
14435
+ }
14436
+ }
14437
+ /**
14438
+ * Connects to the privileged helper, starting it once if needed. It is
14439
+ * reused across instances so a second dev server does not ask for a
14440
+ * password again.
14441
+ */
14442
+ async session() {
14443
+ if (this._session && !this._session.client.connected)
14444
+ this._session = void 0;
14445
+ if (!this._session)
14446
+ this._session = await this.deps.openSession(TEMP_DIR);
14447
+ return this._session;
13981
14448
  }
13982
14449
  async getCaddyfile() {
13983
- if (!(0, import_node_fs3.existsSync)(caddyFilePath)) {
14450
+ if (!(0, import_node_fs4.existsSync)(caddyFilePath)) {
13984
14451
  this.caddyfile = "";
13985
14452
  return "";
13986
14453
  }
@@ -13988,8 +14455,8 @@ var CaddyInstant = class {
13988
14455
  return this.caddyfile;
13989
14456
  }
13990
14457
  get caddyRoot() {
13991
- return (0, import_node_path3.join)(
13992
- import_node_process4.default.platform === "win32" ? `${import_node_process4.default.env.AppData}/Caddy` : `${import_node_process4.default.env.HOME}/Library/Application Support/Caddy`,
14458
+ return (0, import_node_path5.join)(
14459
+ import_node_process7.default.platform === "win32" ? `${import_node_process7.default.env.AppData}/Caddy` : `${import_node_process7.default.env.HOME}/Library/Application Support/Caddy`,
13993
14460
  "./pki/authorities/local"
13994
14461
  );
13995
14462
  }
@@ -14003,6 +14470,33 @@ var CaddyInstant = class {
14003
14470
  await download();
14004
14471
  this.inited = true;
14005
14472
  }
14473
+ /**
14474
+ * Hands the Caddy storage directory back to the developer. Local CA data
14475
+ * created by an earlier root-owned run must stay readable for `tls internal`
14476
+ * to keep serving the same certificate the browser already trusts.
14477
+ */
14478
+ /**
14479
+ * Installs Caddy's local root CA so the browser stops warning about
14480
+ * `tls internal` certificates. Generating the CA and trusting it are separate
14481
+ * steps: a new CA appears whenever the previous one expires or the storage is
14482
+ * replaced, so this runs on every start instead of once.
14483
+ *
14484
+ * The helper owns both the binary path and the command, so nothing here can
14485
+ * be turned into an arbitrary root execution.
14486
+ */
14487
+ async trustLocalCa(session) {
14488
+ try {
14489
+ const result = await session.client.call("ca.trust");
14490
+ if (result.trusted)
14491
+ consola.debug(`Caddy local CA is trusted
14492
+ ${result.output}`);
14493
+ } catch (error) {
14494
+ consola.warn(
14495
+ `could not install the Caddy root certificate automatically: ${error.message}
14496
+ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
14497
+ );
14498
+ }
14499
+ }
14006
14500
  async ensureTlsReady(targetHost) {
14007
14501
  const health = await waitForLocalTls(targetHost);
14008
14502
  if (!health.healthy)
@@ -14054,10 +14548,10 @@ var CaddyInstant = class {
14054
14548
  this._target = target;
14055
14549
  if (!this.inited)
14056
14550
  await this.init();
14551
+ const session = await this.session();
14057
14552
  const sourceHost = splitHostPort(source).host;
14058
14553
  const targetHost = splitHostPort(target).host;
14059
- if (!await addHost(sourceHost, targetHost))
14060
- throw new Error("update host failed");
14554
+ await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
14061
14555
  consola.success("update host success\n");
14062
14556
  const normalizeBase = (b) => {
14063
14557
  let out = b || "/";
@@ -14092,24 +14586,24 @@ var CaddyInstant = class {
14092
14586
  void this.updateCaddyfile();
14093
14587
  })
14094
14588
  );
14095
- if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
14096
- (0, import_node_fs3.writeFileSync)(caddyLockFilePath, "");
14589
+ if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
14590
+ (0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
14097
14591
  if (!this.locked) {
14098
- if (await tryPort(443))
14099
- await kill(443);
14100
- if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
14101
- await kill(80);
14592
+ await session.client.call("port.free", { port: 443 });
14593
+ if (import_node_process7.default.platform === "win32" || !https)
14594
+ await session.client.call("port.free", { port: 80 });
14102
14595
  }
14103
14596
  return new Promise((resolve2, reject2) => {
14104
- var _a4, _b3;
14105
14597
  let startupCheckStarted = false;
14106
14598
  const resolveWhenReady = async () => {
14107
14599
  if (startupCheckStarted)
14108
14600
  return;
14109
14601
  startupCheckStarted = true;
14110
14602
  try {
14111
- if (https)
14603
+ if (https) {
14604
+ await this.trustLocalCa(session);
14112
14605
  await this.ensureTlsReady(targetHost);
14606
+ }
14113
14607
  resolve2();
14114
14608
  } catch (error) {
14115
14609
  if (!this.locked)
@@ -14118,96 +14612,87 @@ var CaddyInstant = class {
14118
14612
  }
14119
14613
  };
14120
14614
  const setupCleanup = () => {
14121
- import_node_process4.default.on("SIGINT", async () => {
14615
+ import_node_process7.default.on("SIGINT", async () => {
14122
14616
  if (this.stoped)
14123
14617
  return;
14124
- import_node_process4.default.stdin.resume();
14618
+ import_node_process7.default.stdin.resume();
14125
14619
  try {
14126
14620
  await this.baseCleanup(restore);
14127
14621
  } finally {
14128
14622
  this.stoped = true;
14129
- import_node_process4.default.nextTick(() => {
14130
- import_node_process4.default.exit();
14623
+ import_node_process7.default.nextTick(() => {
14624
+ import_node_process7.default.exit();
14131
14625
  });
14132
14626
  }
14133
14627
  });
14134
- const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
14135
- import_node_process4.default.exit = async (code) => {
14136
- const port = Number(splitHostPort(source).port);
14137
- if (!Number.isNaN(port) && await tryPort(port))
14138
- await kill(port);
14139
- const pwd = import_node_process4.default.cwd();
14140
- const viteCacheDir = `${pwd}/node_modules/.vite`;
14141
- if ((0, import_node_fs3.existsSync)(viteCacheDir))
14142
- await chmodRecursive(viteCacheDir, 511).catch(() => {
14143
- });
14144
- const viteTempCacheDir = `${pwd}/node_modules/.vite-temp`;
14145
- if ((0, import_node_fs3.existsSync)(viteTempCacheDir))
14146
- await chmodRecursive(viteTempCacheDir, 511).catch(() => {
14147
- });
14148
- const nuxtCacheDir = `${pwd}/.nuxt`;
14149
- if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
14150
- await chmodRecursive(nuxtCacheDir, 511).catch(() => {
14151
- });
14152
- const webpackCacheDir = `${pwd}/node_modules/.cache`;
14153
- if ((0, import_node_fs3.existsSync)(webpackCacheDir))
14154
- await chmodRecursive(webpackCacheDir, 511).catch(() => {
14155
- });
14628
+ const originalExit = import_node_process7.default.exit.bind(import_node_process7.default);
14629
+ import_node_process7.default.exit = async (code) => {
14156
14630
  if (this.stoped)
14157
14631
  return originalExit(code);
14158
- import_node_process4.default.stdin.resume();
14632
+ import_node_process7.default.stdin.resume();
14159
14633
  try {
14160
14634
  await this.baseCleanup();
14161
14635
  } finally {
14162
14636
  this.stoped = true;
14163
- import_node_process4.default.nextTick(() => {
14637
+ import_node_process7.default.nextTick(() => {
14164
14638
  originalExit(code);
14165
14639
  });
14166
14640
  }
14167
14641
  };
14168
14642
  };
14169
14643
  if (!this.locked) {
14170
- this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
14171
14644
  lockfile.lockSync(caddyLockFilePath);
14172
- this._caddyChild.on("error", (err) => {
14173
- return reject2(err);
14174
- });
14175
- (_a4 = this._caddyChild.stderr) == null ? void 0 : _a4.on("data", async (data) => {
14176
- const lines = data.toString().split("\n").map((line) => line.trim());
14177
- for (const line of lines) {
14178
- showCaddyLog && line && console.info(line);
14179
- if (isCaddyReloadCancellation(line)) {
14180
- consola.info("Caddy restarted before TLS issuance completed; retrying.\n");
14181
- continue;
14182
- }
14183
- try {
14184
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
14185
- if (line.includes("parsing caddyfile tokens")) {
14186
- consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
14645
+ setupCleanup();
14646
+ void (async () => {
14647
+ try {
14648
+ const child = new HelperCaddyProcess(session.client);
14649
+ this._caddyChild = child;
14650
+ await session.client.call("caddy.start");
14651
+ child.on("exit", (code) => {
14652
+ if (code !== null && code !== 0)
14653
+ reject2(new Error(`Caddy exited with code ${code}`));
14654
+ });
14655
+ child.stderr.on("data", async (data) => {
14656
+ const lines = data.toString().split("\n").map((line) => line.trim());
14657
+ for (const line of lines) {
14658
+ showCaddyLog && line && console.info(line);
14659
+ if (isCaddyReloadCancellation(line)) {
14660
+ consola.info("Caddy restarted before TLS issuance completed; retrying.\n");
14661
+ continue;
14662
+ }
14663
+ try {
14664
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
14665
+ if (line.includes("parsing caddyfile tokens")) {
14666
+ consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
14187
14667
 
14188
14668
  ${line}
14189
14669
  `);
14190
- await this.baseCleanup();
14191
- import_node_process4.default.exit();
14192
- } else {
14193
- consola.error(`${line}
14670
+ await this.baseCleanup();
14671
+ import_node_process7.default.exit();
14672
+ } else {
14673
+ consola.error(`${line}
14194
14674
  `);
14195
- return reject2(line);
14675
+ return reject2(line);
14676
+ }
14677
+ }
14678
+ } catch {
14196
14679
  }
14680
+ if (line.includes("config file changed"))
14681
+ consola.success("Detect added a new reverse proxy config, restarted.\n");
14682
+ if (line.includes("caddy proxying") || line.includes("serving initial"))
14683
+ void resolveWhenReady();
14197
14684
  }
14198
- } catch {
14199
- }
14200
- if (line.includes("config file changed"))
14201
- consola.success("Detect added a new reverse proxy config, restarted.\n");
14202
- if (line.includes("caddy proxying") || line.includes("serving initial"))
14685
+ });
14686
+ child.stdout.on("data", (data) => {
14687
+ consola.info(data.toString());
14203
14688
  void resolveWhenReady();
14689
+ });
14690
+ } catch (error) {
14691
+ if (!this.locked)
14692
+ await this.baseCleanup(restore);
14693
+ reject2(error);
14204
14694
  }
14205
- });
14206
- (_b3 = this._caddyChild.stdout) == null ? void 0 : _b3.on("data", (_data) => {
14207
- consola.info(_data.toString());
14208
- void resolveWhenReady();
14209
- });
14210
- setupCleanup();
14695
+ })();
14211
14696
  } else {
14212
14697
  consola.info("Caddy is running in another process.");
14213
14698
  void (async () => {
@@ -14224,17 +14709,25 @@ ${line}
14224
14709
  });
14225
14710
  }
14226
14711
  async baseCleanup(restore = true) {
14712
+ var _a4;
14227
14713
  this._stopEffects.forEach((fn) => fn());
14714
+ this._stopEffects.length = 0;
14228
14715
  try {
14229
- if (restore && this._source && this._target) {
14230
- if (await removeHost(splitHostPort(this._source).host, splitHostPort(this._target).host))
14231
- consola.success("Restore host success.\n");
14232
- else
14233
- consola.fail("Restore host failed.\n");
14716
+ if (restore && this._source && this._target && this._session) {
14717
+ const sourceHost = splitHostPort(this._source).host;
14718
+ const targetHost = splitHostPort(this._target).host;
14719
+ await this._session.client.call("hosts.remove", { ip: sourceHost, host: targetHost });
14720
+ if (sourceHost === "localhost")
14721
+ await this._session.client.call("hosts.remove", { ip: "127.0.0.1", host: targetHost });
14722
+ consola.success("Restore host success.\n");
14234
14723
  }
14235
14724
  } catch (e) {
14236
- consola.error(e);
14237
- consola.fail("Restore host failed.\n");
14725
+ if (((_a4 = this._session) == null ? void 0 : _a4.client.connected) === false) {
14726
+ consola.debug("hosts entries are restored by the privileged helper on disconnect");
14727
+ } else {
14728
+ consola.error(e);
14729
+ consola.fail("Restore host failed.\n");
14730
+ }
14238
14731
  }
14239
14732
  if (!this.locked && !this.stoped) {
14240
14733
  await this.stopCaddy();
@@ -14394,7 +14887,7 @@ var hmrSseBridgeClientScript = `
14394
14887
 
14395
14888
  // src/index.ts
14396
14889
  var caddy;
14397
- var cwd = import_node_process5.default.cwd();
14890
+ var cwd = import_node_process8.default.cwd();
14398
14891
  function colorUrl(url2) {
14399
14892
  return import_picocolors2.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
14400
14893
  }
@@ -14451,7 +14944,7 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
14451
14944
  configKey: "unpluginHttpsReverseProxy"
14452
14945
  },
14453
14946
  setup(options, _nuxt) {
14454
- if (import_node_process6.default.env.NODE_ENV !== "development")
14947
+ if (import_node_process9.default.env.NODE_ENV !== "development")
14455
14948
  return;
14456
14949
  const {
14457
14950
  enable = true,
@@ -14459,10 +14952,6 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
14459
14952
  } = options;
14460
14953
  if (!enable)
14461
14954
  return;
14462
- if (!isAdmin()) {
14463
- consola.warn("please run as administrator");
14464
- return;
14465
- }
14466
14955
  if (!target) {
14467
14956
  consola.fail("please provide target");
14468
14957
  return;