unplugin-https-reverse-proxy 4.1.0-beta.11 → 4.1.0-beta.13

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.
@@ -3,17 +3,21 @@ import {
3
3
  } from "./chunk-RKHJN6KY.js";
4
4
 
5
5
  // src/privileged-helper.ts
6
- import process3 from "node:process";
6
+ import { writeFileSync as writeFileSync2 } from "node:fs";
7
+ import { tmpdir } from "node:os";
8
+ import { basename, dirname as dirname2, resolve } from "node:path";
9
+ import process4 from "node:process";
7
10
 
8
11
  // src/privileged/bootstrap.ts
9
12
  import { Buffer } from "node:buffer";
10
13
  import { chmodSync, chownSync, existsSync, readFileSync as readFileSync2, rmSync } from "node:fs";
11
14
  import { createServer } from "node:net";
12
15
  import { dirname, join as join2 } from "node:path";
13
- import process2 from "node:process";
16
+ import process3 from "node:process";
14
17
 
15
18
  // src/privileged/path-guard.ts
16
19
  import { lstatSync } from "node:fs";
20
+ import process from "node:process";
17
21
  function describe(stats) {
18
22
  return `uid=${stats.uid} mode=${(stats.mode & 511).toString(8)}`;
19
23
  }
@@ -42,6 +46,8 @@ function checkPrivilegedPath(path, options) {
42
46
  guidance: "Provide a regular file or directory at this path manually."
43
47
  };
44
48
  }
49
+ if (process.platform === "win32")
50
+ return void 0;
45
51
  const allowedOwner = stats.uid === 0 || options.ownerUid !== void 0 && stats.uid === options.ownerUid;
46
52
  if (!allowedOwner) {
47
53
  return {
@@ -68,7 +74,7 @@ import { execFile, spawn } from "node:child_process";
68
74
  import { lchownSync, lstatSync as lstatSync2, readdirSync, readFileSync, writeFileSync } from "node:fs";
69
75
  import { platform } from "node:os";
70
76
  import { join } from "node:path";
71
- import process from "node:process";
77
+ import process2 from "node:process";
72
78
  import { promisify } from "node:util";
73
79
 
74
80
  // src/privileged/hosts-file.ts
@@ -213,8 +219,8 @@ function isAllowedFreePort(port) {
213
219
  // src/privileged/server.ts
214
220
  var execFileAsync = promisify(execFile);
215
221
  function execFileQuiet(file, args) {
216
- return new Promise((resolve) => {
217
- execFile(file, args, (error, stdout) => resolve({ stdout: error && !stdout ? "" : stdout }));
222
+ return new Promise((resolve2) => {
223
+ execFile(file, args, (error, stdout) => resolve2({ stdout: error && !stdout ? "" : stdout }));
218
224
  });
219
225
  }
220
226
  var HOSTS_PATH = platform() === "win32" ? "C:\\Windows\\System32\\drivers\\etc\\hosts" : "/etc/hosts";
@@ -325,7 +331,7 @@ function createHelperRuntime(deps) {
325
331
  try {
326
332
  switch (request.method) {
327
333
  case "ping":
328
- return { id: request.id, ok: true, result: { pid: process.pid } };
334
+ return { id: request.id, ok: true, result: { pid: process2.pid } };
329
335
  case "hosts.add": {
330
336
  const { ip, host } = request.params;
331
337
  if (!isSafeIp(ip) || !isSafeHost(host))
@@ -456,14 +462,14 @@ async function trustLocalCaWithSystemTools(caddyBin, adminSocket) {
456
462
  }
457
463
  function createNodeHelperDeps(options) {
458
464
  const hostsPath = options.hostsPath ?? HOSTS_PATH;
459
- const log = options.log ?? ((message) => process.stdout.write(`${message}
465
+ const log = options.log ?? ((message) => process2.stdout.write(`${message}
460
466
  `));
461
467
  let caddy;
462
- process.on("exit", () => {
468
+ process2.on("exit", () => {
463
469
  if ((caddy == null ? void 0 : caddy.pid) === void 0)
464
470
  return;
465
471
  try {
466
- process.kill(caddy.pid, "SIGTERM");
472
+ process2.kill(caddy.pid, "SIGTERM");
467
473
  } catch {
468
474
  }
469
475
  });
@@ -489,10 +495,10 @@ function createNodeHelperDeps(options) {
489
495
  const pids = platform() === "win32" ? parseWindowsListeningPids((await execFileAsync("netstat", ["-ano"])).stdout, port) : parseListeningPids((await execFileQuiet("lsof", [`-ti:${port}`, "-sTCP:LISTEN"])).stdout);
490
496
  const killed = [];
491
497
  for (const pid of pids) {
492
- if (pid === process.pid || keepPid !== void 0 && pid === keepPid)
498
+ if (pid === process2.pid || keepPid !== void 0 && pid === keepPid)
493
499
  continue;
494
500
  try {
495
- process.kill(pid, "SIGTERM");
501
+ process2.kill(pid, "SIGTERM");
496
502
  killed.push(pid);
497
503
  } catch {
498
504
  }
@@ -501,7 +507,7 @@ function createNodeHelperDeps(options) {
501
507
  },
502
508
  caddyBin: options.caddyBin,
503
509
  caddyConfigPath: options.caddyConfigPath,
504
- caddyCwd: options.caddyCwd ?? process.cwd(),
510
+ caddyCwd: options.caddyCwd ?? process2.cwd(),
505
511
  caddyEnv: options.caddyEnv ?? {},
506
512
  trustLocalCa: () => trustLocalCaWithSystemTools(options.caddyBin, options.caddyAdminSocket),
507
513
  caddyStoragePath: options.caddyStoragePath,
@@ -509,8 +515,8 @@ function createNodeHelperDeps(options) {
509
515
  startCaddy: (emit) => {
510
516
  var _a, _b;
511
517
  const child = spawn(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
512
- cwd: options.caddyCwd ?? process.cwd(),
513
- env: { ...process.env, ...options.caddyEnv },
518
+ cwd: options.caddyCwd ?? process2.cwd(),
519
+ env: { ...process2.env, ...options.caddyEnv },
514
520
  stdio: ["ignore", "pipe", "pipe"],
515
521
  detached: platform() !== "win32"
516
522
  });
@@ -579,7 +585,7 @@ var HANDSHAKE_TIMEOUT_MS = 12e4;
579
585
  var DEFAULT_IDLE_TIMEOUT_MS = 3e4;
580
586
  async function startHelper(options) {
581
587
  const { socketPath, token } = options;
582
- const log = options.log ?? ((message) => process2.stdout.write(`[uhrp-helper] ${message}
588
+ const log = options.log ?? ((message) => process3.stdout.write(`[uhrp-helper] ${message}
583
589
  `));
584
590
  for (const check of [
585
591
  checkPrivilegedPath(options.caddyBin, { label: "Caddy binary", ownerUid: options.ownerUid }),
@@ -660,7 +666,7 @@ async function startHelper(options) {
660
666
  return;
661
667
  }
662
668
  authenticated = true;
663
- socket.write(`${JSON.stringify({ type: "handshake", ok: true, pid: process2.pid })}
669
+ socket.write(`${JSON.stringify({ type: "handshake", ok: true, pid: process3.pid })}
664
670
  `);
665
671
  attachSocket(socket, runtime, log);
666
672
  if (rest.trim() !== "")
@@ -685,21 +691,21 @@ async function startHelper(options) {
685
691
  server.close();
686
692
  return;
687
693
  }
688
- server.close(() => process2.exit(0));
689
- (_b = (_a2 = setTimeout(() => process2.exit(0), 1e3)).unref) == null ? void 0 : _b.call(_a2);
694
+ server.close(() => process3.exit(0));
695
+ (_b = (_a2 = setTimeout(() => process3.exit(0), 1e3)).unref) == null ? void 0 : _b.call(_a2);
690
696
  }, idleTimeoutMs);
691
697
  (_a = idleTimer.unref) == null ? void 0 : _a.call(idleTimer);
692
698
  }
693
- await new Promise((resolve, reject) => {
699
+ await new Promise((resolve2, reject) => {
694
700
  server.once("error", reject);
695
- server.listen(socketPath, () => resolve());
701
+ const shareWithUser = process3.platform === "win32";
702
+ server.listen({ path: socketPath, readableAll: shareWithUser, writableAll: shareWithUser }, () => resolve2());
696
703
  });
697
704
  scheduleIdleExit();
698
705
  try {
699
- if (typeof options.ownerUid === "number") {
700
- chownSync(socketPath, options.ownerUid, options.ownerGid ?? options.ownerUid);
701
- chmodSync(socketPath, 384);
702
- } else {
706
+ if (process3.platform !== "win32") {
707
+ if (typeof options.ownerUid === "number")
708
+ chownSync(socketPath, options.ownerUid, options.ownerGid ?? options.ownerUid);
703
709
  chmodSync(socketPath, 384);
704
710
  }
705
711
  } catch (error) {
@@ -711,14 +717,14 @@ async function startHelper(options) {
711
717
  for (const socket of connections)
712
718
  socket.destroy();
713
719
  connections.clear();
714
- await new Promise((resolve) => {
715
- server.close(() => resolve());
720
+ await new Promise((resolve2) => {
721
+ server.close(() => resolve2());
716
722
  });
717
723
  }
718
724
  };
719
725
  }
720
726
  function removeOwnSocket(socketPath, token) {
721
- if (process2.platform === "win32")
727
+ if (process3.platform === "win32")
722
728
  return;
723
729
  try {
724
730
  const tokensDir = dirname(socketPath);
@@ -783,7 +789,7 @@ function parseArgs(argv) {
783
789
  };
784
790
  }
785
791
  async function main() {
786
- const args = parseArgs(process3.argv.slice(2));
792
+ const args = parseArgs(process4.argv.slice(2));
787
793
  const helper = await startHelper({
788
794
  socketPath: args.socket,
789
795
  token: args.token,
@@ -795,27 +801,41 @@ async function main() {
795
801
  caddyStoragePath: args.caddyStorage,
796
802
  caddyAdminSocket: args.caddyAdmin,
797
803
  caddyEnv: {
798
- HOME: process3.env.HOME ?? "",
804
+ HOME: process4.env.HOME ?? "",
799
805
  // Keep Caddy's storage next to the invoking user's home even though the
800
806
  // process runs as root.
801
- XDG_DATA_HOME: process3.env.XDG_DATA_HOME ?? ""
807
+ XDG_DATA_HOME: process4.env.XDG_DATA_HOME ?? ""
802
808
  }
803
809
  });
804
810
  for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
805
- process3.on(signal, () => {
811
+ process4.on(signal, () => {
806
812
  });
807
- process3.on("SIGTERM", () => {
813
+ process4.on("SIGTERM", () => {
808
814
  if (helper.runtime.clientCount() > 0)
809
815
  return;
810
- void helper.runtime.dispose().finally(() => process3.exit(0));
816
+ void helper.runtime.dispose().finally(() => process4.exit(0));
811
817
  });
812
- process3.stdout.on("error", () => {
818
+ process4.stdout.on("error", () => {
813
819
  });
814
- process3.stderr.on("error", () => {
820
+ process4.stderr.on("error", () => {
815
821
  });
816
822
  }
817
823
  main().catch((error) => {
818
- process3.stderr.write(`[uhrp-helper] fatal: ${error.message}
824
+ process4.stderr.write(`[uhrp-helper] fatal: ${error.message}
819
825
  `);
820
- process3.exit(1);
826
+ const errorFile = errorFileFrom(process4.argv.slice(2));
827
+ if (errorFile) {
828
+ try {
829
+ writeFileSync2(errorFile, error.message, { flag: "wx" });
830
+ } catch {
831
+ }
832
+ }
833
+ process4.exit(1);
821
834
  });
835
+ function errorFileFrom(argv) {
836
+ const index = argv.indexOf("--error-file");
837
+ const path = index >= 0 ? argv[index + 1] : void 0;
838
+ if (!path || !/^uhrp-helper-[0-9a-f]+\.log$/.test(basename(path)))
839
+ return void 0;
840
+ return resolve(dirname2(path)) === resolve(tmpdir()) ? path : void 0;
841
+ }
package/dist/rollup.cjs CHANGED
@@ -43,10 +43,10 @@ var import_unplugin = require("unplugin");
43
43
 
44
44
  // src/caddy/index.ts
45
45
  var import_node_child_process3 = require("child_process");
46
- var import_node_fs4 = require("fs");
46
+ var import_node_fs5 = require("fs");
47
47
  var import_promises2 = require("fs/promises");
48
48
  var import_node_os5 = require("os");
49
- var import_node_path5 = require("path");
49
+ var import_node_path6 = require("path");
50
50
  var import_node_process8 = __toESM(require("process"), 1);
51
51
  var import_got_cjs = require("got-cjs");
52
52
  var import_http_proxy_agent = require("http-proxy-agent");
@@ -13295,7 +13295,7 @@ function isCaddyReloadCancellation(line) {
13295
13295
  // src/caddy/privileged.ts
13296
13296
  var import_node_buffer2 = require("buffer");
13297
13297
  var import_node_events = require("events");
13298
- var import_node_path4 = require("path");
13298
+ var import_node_path5 = require("path");
13299
13299
  var import_node_process7 = __toESM(require("process"), 1);
13300
13300
  var import_node_url = require("url");
13301
13301
 
@@ -13331,16 +13331,18 @@ function findUp(from, relative, exists2) {
13331
13331
 
13332
13332
  // src/privileged/session.ts
13333
13333
  var import_node_buffer = require("buffer");
13334
- var import_node_fs3 = require("fs");
13334
+ var import_node_fs4 = require("fs");
13335
13335
  var import_promises = require("fs/promises");
13336
13336
  var import_node_os4 = require("os");
13337
- var import_node_path3 = require("path");
13337
+ var import_node_path4 = require("path");
13338
13338
  var lockfile2 = __toESM(require("proper-lockfile"), 1);
13339
13339
 
13340
13340
  // src/privileged/launch.ts
13341
13341
  var import_node_child_process2 = require("child_process");
13342
13342
  var import_node_crypto = require("crypto");
13343
+ var import_node_fs3 = require("fs");
13343
13344
  var import_node_os3 = require("os");
13345
+ var import_node_path3 = require("path");
13344
13346
  var import_node_process6 = __toESM(require("process"), 1);
13345
13347
 
13346
13348
  // src/privileged/client.ts
@@ -13454,7 +13456,7 @@ async function connectClient(options) {
13454
13456
  } catch (error) {
13455
13457
  lastError = error;
13456
13458
  const code = lastError.code;
13457
- if (code === "EACCES" || lastError instanceof HelperConnectionError)
13459
+ if (code === "EACCES" || code === "EPERM" || lastError instanceof HelperConnectionError)
13458
13460
  throw lastError;
13459
13461
  await new Promise((resolve2) => setTimeout(resolve2, retryIntervalMs));
13460
13462
  }
@@ -13586,39 +13588,78 @@ function createClient(socket, initialBuffer, callTimeoutMs) {
13586
13588
  // src/privileged/windows-elevation.ts
13587
13589
  var import_node_child_process = require("child_process");
13588
13590
  var import_node_process5 = __toESM(require("process"), 1);
13591
+ var ERROR_CANCELLED = 1223;
13589
13592
  function quotePowerShell(value2) {
13590
13593
  return `'${value2.replace(/'/g, "''")}'`;
13591
13594
  }
13595
+ function quoteWindowsArg(arg) {
13596
+ if (arg === "")
13597
+ return '""';
13598
+ if (!/[\s"]/.test(arg))
13599
+ return arg;
13600
+ let quoted = '"';
13601
+ let backslashes = 0;
13602
+ for (const char of arg) {
13603
+ if (char === "\\") {
13604
+ backslashes++;
13605
+ continue;
13606
+ }
13607
+ quoted += char === '"' ? `${"\\".repeat(backslashes * 2 + 1)}"` : `${"\\".repeat(backslashes)}${char}`;
13608
+ backslashes = 0;
13609
+ }
13610
+ return `${quoted}${"\\".repeat(backslashes * 2)}"`;
13611
+ }
13592
13612
  function buildElevationCommand(options) {
13593
- const argumentList = options.args.map(quotePowerShell).join(",");
13594
- const parts = [
13595
- "Start-Process",
13596
- "-FilePath",
13597
- quotePowerShell(options.file)
13613
+ const lines = [
13614
+ // The message read back on failure is localized; keep it readable as UTF-8.
13615
+ "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8",
13616
+ "$psi = New-Object System.Diagnostics.ProcessStartInfo",
13617
+ `$psi.FileName = ${quotePowerShell(options.file)}`,
13618
+ `$psi.Arguments = ${quotePowerShell(options.args.map(quoteWindowsArg).join(" "))}`
13598
13619
  ];
13599
- if (argumentList)
13600
- parts.push("-ArgumentList", argumentList);
13601
13620
  if (options.cwd)
13602
- parts.push("-WorkingDirectory", quotePowerShell(options.cwd));
13603
- parts.push("-Verb", "RunAs");
13604
- parts.push("-WindowStyle", "Hidden");
13605
- return parts.join(" ");
13621
+ lines.push(`$psi.WorkingDirectory = ${quotePowerShell(options.cwd)}`);
13622
+ lines.push(
13623
+ "$psi.Verb = 'runas'",
13624
+ "$psi.UseShellExecute = $true",
13625
+ "$psi.WindowStyle = 'Hidden'",
13626
+ "try { $p = [System.Diagnostics.Process]::Start($psi); if ($p) { [Console]::Out.Write($p.Id) } }",
13627
+ `catch { $e = $_.Exception; while ($e.InnerException) { $e = $e.InnerException }; if ($e.NativeErrorCode -eq ${ERROR_CANCELLED}) { exit ${ERROR_CANCELLED} }; [Console]::Error.Write($e.Message); exit 1 }`
13628
+ );
13629
+ return lines.join("\n");
13606
13630
  }
13607
13631
  function spawnElevatedOnWindows(options) {
13608
- return new Promise((resolve2, reject2) => {
13609
- const script = buildElevationCommand(options);
13632
+ return new Promise((resolve2) => {
13610
13633
  const child = (0, import_node_child_process.spawn)(
13611
13634
  "powershell.exe",
13612
- ["-NoProfile", "-NonInteractive", "-Command", script],
13613
- { stdio: "ignore", windowsHide: true }
13635
+ ["-NoProfile", "-NonInteractive", "-Command", buildElevationCommand(options)],
13636
+ { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }
13614
13637
  );
13615
- child.once("error", reject2);
13616
- child.once("exit", (code) => {
13617
- if (code === 0)
13618
- return resolve2(child);
13619
- reject2(new Error(
13620
- `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.`
13621
- ));
13638
+ let stdout = "";
13639
+ let stderr = "";
13640
+ child.stdout.on("data", (data) => {
13641
+ stdout += data.toString();
13642
+ });
13643
+ child.stderr.on("data", (data) => {
13644
+ stderr = (stderr + data.toString()).slice(-4096);
13645
+ });
13646
+ child.once("error", (error) => resolve2({
13647
+ ok: false,
13648
+ denied: false,
13649
+ message: `could not start PowerShell to request administrator permission: ${error.message}`
13650
+ }));
13651
+ child.once("close", (code) => {
13652
+ if (code === 0) {
13653
+ const pid = Number(stdout.trim());
13654
+ return resolve2({ ok: true, pid: Number.isSafeInteger(pid) && pid > 0 ? pid : void 0 });
13655
+ }
13656
+ if (code === ERROR_CANCELLED)
13657
+ return resolve2({ ok: false, denied: true, message: "administrator permission was cancelled" });
13658
+ resolve2({
13659
+ ok: false,
13660
+ denied: false,
13661
+ message: `could not start the privileged helper as administrator (PowerShell exited with ${code}).${stderr.trim() ? ` ${stderr.trim()}` : ""}`
13662
+ });
13622
13663
  });
13623
13664
  });
13624
13665
  }
@@ -13749,8 +13790,18 @@ async function startPrivilegedHelper(options) {
13749
13790
  ...options.caddyAdminSocket ? ["--caddy-admin", options.caddyAdminSocket] : []
13750
13791
  ];
13751
13792
  let child;
13793
+ let helperExited;
13752
13794
  if (!direct && (0, import_node_os3.platform)() === "win32") {
13753
- await spawnElevatedOnWindows({ file: helperEntry, args: childArgv, cwd: import_node_process6.default.cwd() });
13795
+ const errorFile = (0, import_node_path3.join)((0, import_node_os3.tmpdir)(), `uhrp-helper-${(0, import_node_crypto.randomBytes)(6).toString("hex")}.log`);
13796
+ const elevated = await spawnElevatedOnWindows({
13797
+ file: helperEntry,
13798
+ args: [...childArgv, "--error-file", errorFile],
13799
+ cwd: import_node_process6.default.cwd()
13800
+ });
13801
+ if (!elevated.ok)
13802
+ throw elevated.denied ? new PrivilegeDeniedError(elevated.message) : new Error(elevated.message);
13803
+ if (elevated.pid !== void 0)
13804
+ helperExited = watchWindowsHelper(elevated.pid, errorFile);
13754
13805
  } else {
13755
13806
  const command = direct ? helperEntry : sudoCommand;
13756
13807
  const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
@@ -13784,7 +13835,10 @@ async function startPrivilegedHelper(options) {
13784
13835
  }
13785
13836
  }
13786
13837
  try {
13787
- const client = await connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
13838
+ const connecting = connectClient({ socketPath, token, timeoutMs: connectTimeoutMs });
13839
+ connecting.catch(() => {
13840
+ });
13841
+ const client = await (helperExited ? Promise.race([connecting, helperExited.promise]) : connecting);
13788
13842
  return {
13789
13843
  client,
13790
13844
  async close() {
@@ -13799,6 +13853,42 @@ async function startPrivilegedHelper(options) {
13799
13853
  } catch {
13800
13854
  }
13801
13855
  throw error;
13856
+ } finally {
13857
+ helperExited == null ? void 0 : helperExited.stop();
13858
+ }
13859
+ }
13860
+ function watchWindowsHelper(pid, errorFile) {
13861
+ let timer;
13862
+ const promise = new Promise((_, reject2) => {
13863
+ timer = setInterval(() => {
13864
+ if (isProcessRunning(pid))
13865
+ return;
13866
+ clearInterval(timer);
13867
+ let detail = "";
13868
+ try {
13869
+ detail = (0, import_node_fs3.readFileSync)(errorFile, "utf8").trim().slice(-4096);
13870
+ } catch {
13871
+ }
13872
+ reject2(new Error(`privileged helper exited before accepting connections.${detail ? ` ${detail}` : " No diagnostic output from the helper."}`));
13873
+ }, 250);
13874
+ });
13875
+ return {
13876
+ promise,
13877
+ stop() {
13878
+ clearInterval(timer);
13879
+ try {
13880
+ (0, import_node_fs3.rmSync)(errorFile, { force: true });
13881
+ } catch {
13882
+ }
13883
+ }
13884
+ };
13885
+ }
13886
+ function isProcessRunning(pid) {
13887
+ try {
13888
+ import_node_process6.default.kill(pid, 0);
13889
+ return true;
13890
+ } catch (error) {
13891
+ return error.code !== "ESRCH";
13802
13892
  }
13803
13893
  }
13804
13894
  async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
@@ -13811,12 +13901,12 @@ async function connectExistingHelper(socketPath, token, timeoutMs = 1500) {
13811
13901
 
13812
13902
  // src/privileged/session.ts
13813
13903
  function tokenPath(runtimeDir) {
13814
- return (0, import_node_path3.join)(runtimeDir, "helper.token");
13904
+ return (0, import_node_path4.join)(runtimeDir, "helper.token");
13815
13905
  }
13816
13906
  function sessionSocketPath(runtimeDir) {
13817
13907
  if ((0, import_node_os4.platform)() === "win32")
13818
13908
  return `\\\\.\\pipe\\uhrp-${import_node_buffer.Buffer.from(runtimeDir).toString("hex").slice(0, 40)}`;
13819
- return (0, import_node_path3.join)(runtimeDir, "helper.sock");
13909
+ return (0, import_node_path4.join)(runtimeDir, "helper.sock");
13820
13910
  }
13821
13911
  async function openHelperSession(scope2) {
13822
13912
  const socketPath = sessionSocketPath(scope2.runtimeDir);
@@ -13831,7 +13921,7 @@ async function openHelperSession(scope2) {
13831
13921
  }
13832
13922
  }
13833
13923
  async function tryReuse(socketPath, scope2) {
13834
- if (!(0, import_node_fs3.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
13924
+ if (!(0, import_node_fs4.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
13835
13925
  return void 0;
13836
13926
  const token = await readToken(scope2.runtimeDir);
13837
13927
  if (!token)
@@ -13875,7 +13965,7 @@ async function startNew(socketPath, scope2) {
13875
13965
  };
13876
13966
  }
13877
13967
  async function acquireStartLock(runtimeDir) {
13878
- const lockPath = (0, import_node_path3.join)(runtimeDir, "helper.start.lock");
13968
+ const lockPath = (0, import_node_path4.join)(runtimeDir, "helper.start.lock");
13879
13969
  try {
13880
13970
  await (0, import_promises.writeFile)(lockPath, "", { flag: "a" });
13881
13971
  } catch {
@@ -13909,7 +13999,7 @@ async function writeToken(runtimeDir, token) {
13909
13999
  // src/caddy/privileged.ts
13910
14000
  var import_meta = {};
13911
14001
  function resolvePrivilegedEnv() {
13912
- const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path4.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
14002
+ const moduleDir = typeof __dirname === "string" ? __dirname : (0, import_node_path5.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
13913
14003
  const resolved = resolveHelperEntry({ moduleDir });
13914
14004
  return { helperEntry: resolved.entry, helperArgs: resolved.args };
13915
14005
  }
@@ -13949,7 +14039,7 @@ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
13949
14039
  }
13950
14040
  };
13951
14041
  function caddyStoragePath() {
13952
- return import_node_process7.default.platform === "win32" ? (0, import_node_path4.join)(import_node_process7.default.env.AppData ?? "", "Caddy") : (0, import_node_path4.join)(import_node_process7.default.env.HOME ?? "", "Library/Application Support/Caddy");
14042
+ return import_node_process7.default.platform === "win32" ? (0, import_node_path5.join)(import_node_process7.default.env.AppData ?? "", "Caddy") : (0, import_node_path5.join)(import_node_process7.default.env.HOME ?? "", "Library/Application Support/Caddy");
13953
14043
  }
13954
14044
  function openPrivilegedSession(runtimeDir, options) {
13955
14045
  const env2 = resolvePrivilegedEnv();
@@ -14093,11 +14183,11 @@ async function download() {
14093
14183
  if (await testCaddy())
14094
14184
  return caddyPath;
14095
14185
  return new Promise((resolve2, reject2) => {
14096
- if (!(0, import_node_fs4.existsSync)(TEMP_DIR)) {
14097
- (0, import_node_fs4.mkdirSync)(TEMP_DIR, { recursive: true });
14098
- (0, import_node_fs4.chmodSync)(TEMP_DIR, 448);
14186
+ if (!(0, import_node_fs5.existsSync)(TEMP_DIR)) {
14187
+ (0, import_node_fs5.mkdirSync)(TEMP_DIR, { recursive: true });
14188
+ (0, import_node_fs5.chmodSync)(TEMP_DIR, 448);
14099
14189
  }
14100
- const file = (0, import_node_fs4.createWriteStream)(caddyPath);
14190
+ const file = (0, import_node_fs5.createWriteStream)(caddyPath);
14101
14191
  let _platform = (0, import_node_os5.platform)().toString();
14102
14192
  _platform === "win32" && (_platform = "windows");
14103
14193
  let _arch = import_node_process8.default.arch.toString();
@@ -14106,13 +14196,13 @@ async function download() {
14106
14196
  if (!support)
14107
14197
  return reject2(new Error("not support"));
14108
14198
  const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
14109
- (0, import_node_fs4.existsSync)(caddyPath) && (0, import_node_fs4.unlinkSync)(caddyPath);
14199
+ (0, import_node_fs5.existsSync)(caddyPath) && (0, import_node_fs5.unlinkSync)(caddyPath);
14110
14200
  const httpProxy = import_node_process8.default.env.HTTP_PROXY || import_node_process8.default.env.http_proxy;
14111
14201
  const httpsProxy = import_node_process8.default.env.HTTPS_PROXY || import_node_process8.default.env.https_proxy;
14112
14202
  const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
14113
14203
  const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
14114
14204
  const chmodCaddyOnce = once(() => {
14115
- (0, import_node_fs4.chmodSync)(caddyPath, 493);
14205
+ (0, import_node_fs5.chmodSync)(caddyPath, 493);
14116
14206
  });
14117
14207
  import_got_cjs.got.stream(dowmloadLink, {
14118
14208
  agent: {
@@ -14126,7 +14216,7 @@ async function download() {
14126
14216
  logProgressOver();
14127
14217
  if (import_node_process8.default.platform === "win32")
14128
14218
  return resolve2(caddyPath);
14129
- (0, import_node_fs4.chmodSync)(caddyPath, 493);
14219
+ (0, import_node_fs5.chmodSync)(caddyPath, 493);
14130
14220
  resolve2(caddyPath);
14131
14221
  }).on("error", (err) => {
14132
14222
  reject2(err);
@@ -14135,10 +14225,10 @@ async function download() {
14135
14225
  }
14136
14226
  function testCaddy() {
14137
14227
  return new Promise((resolve2) => {
14138
- if (!(0, import_node_fs4.existsSync)(caddyPath))
14228
+ if (!(0, import_node_fs5.existsSync)(caddyPath))
14139
14229
  return resolve2(false);
14140
14230
  try {
14141
- (0, import_node_fs4.chmodSync)(caddyPath, 493);
14231
+ (0, import_node_fs5.chmodSync)(caddyPath, 493);
14142
14232
  } catch {
14143
14233
  }
14144
14234
  (0, import_node_child_process3.execFile)(caddyPath, [], { timeout: 1e4 }, (error, stdout) => {
@@ -14149,7 +14239,7 @@ function testCaddy() {
14149
14239
  });
14150
14240
  }
14151
14241
  function caddyRootPath() {
14152
- return (0, import_node_path5.join)(
14242
+ return (0, import_node_path6.join)(
14153
14243
  import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
14154
14244
  "./pki/authorities/local"
14155
14245
  );
@@ -14212,12 +14302,14 @@ var CaddyInstant = class {
14212
14302
  async session(reason) {
14213
14303
  if (this._session && !this._session.client.connected)
14214
14304
  this._session = void 0;
14215
- if (!this._session)
14305
+ if (!this._session) {
14306
+ await this.deps.config().writeCaddyConfig([], this.proxyKey);
14216
14307
  this._session = await this.deps.openSession(TEMP_DIR, reason);
14308
+ }
14217
14309
  return this._session;
14218
14310
  }
14219
14311
  async getCaddyfile() {
14220
- if (!(0, import_node_fs4.existsSync)(caddyFilePath)) {
14312
+ if (!(0, import_node_fs5.existsSync)(caddyFilePath)) {
14221
14313
  this.caddyfile = "";
14222
14314
  return "";
14223
14315
  }
@@ -14782,6 +14874,8 @@ var unpluginFactory = (options) => ({
14782
14874
  return;
14783
14875
  }
14784
14876
  const _printUrls = server.printUrls.bind(server);
14877
+ if (server.config.server.middlewareMode)
14878
+ consola.warn("Vite runs in middleware mode, so the reverse proxy cannot start from the Vite plugin. In Nuxt, add `unplugin-https-reverse-proxy/nuxt` to `modules` instead.");
14785
14879
  let source = `localhost:${config.server.port || 5173}`;
14786
14880
  const url2 = (_a4 = server.resolvedUrls) == null ? void 0 : _a4.local[0];
14787
14881
  if (url2) {
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-AQLHWJ4E.js";
3
+ } from "./chunk-U6J2RMIR.js";
4
4
  import "./chunk-EY3HXBJ4.js";
5
5
  import "./chunk-C5A7XLKL.js";
6
6
  import "./chunk-WOMR3ZLM.js";