unplugin-https-reverse-proxy 1.0.0 → 2.0.1

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.
package/dist/rollup.cjs CHANGED
@@ -37,15 +37,38 @@ var import_unplugin2 = require("unplugin");
37
37
 
38
38
  // src/index.ts
39
39
  var import_node_process5 = __toESM(require("process"), 1);
40
+ var import_console_table_printer = require("console-table-printer");
41
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
40
42
  var import_unplugin = require("unplugin");
41
- var import_picocolors = __toESM(require("picocolors"), 1);
43
+
44
+ // src/caddy/index.ts
45
+ var import_node_child_process4 = require("child_process");
46
+ var import_node_fs2 = require("fs");
47
+ var import_promises2 = require("fs/promises");
48
+ var import_node_os3 = require("os");
49
+ var import_node_path3 = require("path");
50
+ var import_node_process4 = __toESM(require("process"), 1);
51
+ var import_got_cjs = require("got-cjs");
52
+ var import_http_proxy_agent = require("http-proxy-agent");
53
+ var import_https_proxy_agent = require("https-proxy-agent");
54
+ var lockfile = __toESM(require("proper-lockfile"), 1);
55
+
56
+ // src/host/index.ts
57
+ var import_node_child_process2 = require("child_process");
58
+ var import_node_fs = require("fs");
59
+ var import_node_process2 = __toESM(require("process"), 1);
60
+ var import_node_util = require("util");
61
+ var import_hostile = __toESM(require("hostile"), 1);
42
62
 
43
63
  // src/utils.ts
44
- var import_node_process = __toESM(require("process"), 1);
45
- var import_node_path = __toESM(require("path"), 1);
46
- var import_promises = require("fs/promises");
47
64
  var import_node_child_process = require("child_process");
65
+ var import_promises = require("fs/promises");
66
+ var import_node_os = require("os");
67
+ var import_node_path = __toESM(require("path"), 1);
68
+ var import_node_process = __toESM(require("process"), 1);
48
69
  var import_consola = require("consola");
70
+ var import_picocolors = __toESM(require("picocolors"), 1);
71
+ var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
49
72
  var consola = (0, import_consola.createConsola)({
50
73
  level: 3
51
74
  }).withTag("reverse-proxy");
@@ -75,37 +98,34 @@ function isAdmin() {
75
98
  return false;
76
99
  }
77
100
  } else {
78
- return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
101
+ return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
79
102
  }
80
103
  }
81
-
82
- // src/caddy/index.ts
83
- var import_node_os2 = require("os");
84
- var import_node_process4 = __toESM(require("process"), 1);
85
- var import_node_fs2 = require("fs");
86
- var import_node_child_process4 = require("child_process");
87
- var import_promises2 = require("fs/promises");
88
- var import_got_cjs = require("got-cjs");
89
- var import_http_proxy_agent = require("http-proxy-agent");
90
- var import_https_proxy_agent = require("https-proxy-agent");
91
- var lockfile = __toESM(require("proper-lockfile"), 1);
104
+ function getIpv4List() {
105
+ const interfaces = (0, import_node_os.networkInterfaces)();
106
+ return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
107
+ (detail) => detail.address && (detail.family === "IPv4" || detail.family === 4)
108
+ ).filter((detail) => detail.family === "IPv4" && !detail.internal).map((detail) => detail.address);
109
+ }
110
+ async function generateQrcode(input) {
111
+ return new Promise((resolve) => {
112
+ import_qrcode_terminal.default.generate(input, { small: true }, (code) => {
113
+ resolve(code.split("\n").map((line) => import_picocolors.default.bgBlack(import_picocolors.default.white(line))).join("\n"));
114
+ });
115
+ });
116
+ }
92
117
 
93
118
  // src/host/index.ts
94
- var import_node_process2 = __toESM(require("process"), 1);
95
- var import_node_child_process2 = require("child_process");
96
- var import_node_fs = require("fs");
97
- var import_node_util = require("util");
98
- var import_hostile = __toESM(require("hostile"), 1);
99
119
  var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
100
120
  var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
101
121
  function getPathOfSystemHostsPath() {
102
122
  return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
103
123
  }
104
124
  async function syncHost() {
105
- return new Promise((resolve, reject) => {
125
+ return new Promise((resolve, _reject) => {
106
126
  (0, import_node_child_process2.exec)(
107
127
  import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
108
- (error, stdout, stderr) => {
128
+ (error, _stdout, _stderr) => {
109
129
  if (error) {
110
130
  consola.error(`exec error: ${error}`);
111
131
  return resolve(false);
@@ -134,8 +154,8 @@ async function removeHost(ip, host) {
134
154
  }
135
155
 
136
156
  // src/caddy/constants.ts
157
+ var import_node_os2 = __toESM(require("os"), 1);
137
158
  var import_node_path2 = require("path");
138
- var import_node_os = __toESM(require("os"), 1);
139
159
  var import_node_process3 = __toESM(require("process"), 1);
140
160
  var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
141
161
  import_dotenv_flow.default.config({
@@ -143,7 +163,7 @@ import_dotenv_flow.default.config({
143
163
  });
144
164
  function resolvePath(path2) {
145
165
  if (path2.startsWith("~"))
146
- return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
166
+ return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
147
167
  return path2;
148
168
  }
149
169
  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");
@@ -262,12 +282,12 @@ var supportList = [
262
282
  ];
263
283
 
264
284
  // src/caddy/utils.ts
265
- var import_node_net = require("net");
266
285
  var import_node_child_process3 = require("child_process");
286
+ var import_node_net = require("net");
267
287
  var import_ora = __toESM(require("ora"), 1);
268
288
  var spinner;
269
289
  function tryPort(port) {
270
- return new Promise((resolve, reject) => {
290
+ return new Promise((resolve, _reject) => {
271
291
  try {
272
292
  const server = (0, import_node_net.createServer)().listen(port);
273
293
  server.on("listening", () => {
@@ -279,14 +299,14 @@ function tryPort(port) {
279
299
  resolve(true);
280
300
  server.close();
281
301
  });
282
- } catch (e) {
302
+ } catch {
283
303
  resolve(true);
284
304
  }
285
305
  });
286
306
  }
287
307
  async function kill(port) {
288
308
  return new Promise((resolve, reject) => {
289
- (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
309
+ (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
290
310
  if (err) {
291
311
  reject(err);
292
312
  } else {
@@ -339,14 +359,14 @@ async function download() {
339
359
  (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
340
360
  }
341
361
  const file = (0, import_node_fs2.createWriteStream)(caddyPath);
342
- let _platform = (0, import_node_os2.platform)().toString();
362
+ let _platform = (0, import_node_os3.platform)().toString();
343
363
  _platform === "win32" && (_platform = "windows");
344
364
  let _arch = import_node_process4.default.arch.toString();
345
365
  _arch === "x64" && (_arch = "amd64");
346
366
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
347
367
  if (!support)
348
368
  return reject(new Error("not support"));
349
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
369
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
350
370
  (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
351
371
  const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
352
372
  const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
@@ -420,7 +440,27 @@ var CaddyInstant = class {
420
440
  debug
421
441
  auto_https disable_redirects
422
442
  }
423
-
443
+
444
+ :7601 {
445
+ root * "${(0, import_node_path3.join)(
446
+ import_node_process4.default.platform === "win32" ? `${import_node_process4.default.env.AppData}/Caddy` : `${import_node_process4.default.env.HOME}/Library/Application Support/Caddy`,
447
+ "./pki/authorities/local"
448
+ )}"
449
+ file_server browse
450
+ }
451
+
452
+ # \u6B63\u5411\u4EE3\u7406\u914D\u7F6E
453
+ :7600 {
454
+ bind 0.0.0.0
455
+
456
+ forward_proxy {
457
+ hide_ip
458
+ hide_via
459
+ acl {
460
+ allow all
461
+ }
462
+ }
463
+ }
424
464
  `;
425
465
  await (0, import_promises2.writeFile)(caddyFilePath, contet);
426
466
  this.caddyfile = contet;
@@ -438,7 +478,6 @@ var CaddyInstant = class {
438
478
  /**
439
479
  * @param source like `127.0.0.1:8080`
440
480
  * @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
441
- * @returns
442
481
  */
443
482
  async run(source, target, options) {
444
483
  source = source.replace("0.0.0.0", "127.0.0.1");
@@ -483,7 +522,6 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
483
522
  }
484
523
  }
485
524
  }
486
-
487
525
  `;
488
526
  await this.writeCaddyfile();
489
527
  }
@@ -617,6 +655,38 @@ ${line}
617
655
  var config;
618
656
  var caddy;
619
657
  var cwd = import_node_process5.default.cwd();
658
+ function colorUrl(url) {
659
+ return import_picocolors2.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
660
+ }
661
+ async function printForwardProxy() {
662
+ const ipv4List = getIpv4List();
663
+ if (ipv4List.length) {
664
+ const ips = ipv4List.map((ip) => import_picocolors2.default.cyan(ip)).join(", ");
665
+ consola.info(`${import_picocolors2.default.bold("Mobile device proxy access")}:
666
+ `);
667
+ consola.info("1. Install certificate: scan the QR code and download the `root.crt` file,");
668
+ consola.info(" then install it on your mobile device");
669
+ const ipTable = await Promise.all(
670
+ ipv4List.map(async (ip) => ({
671
+ target: `http://${ip}:7601`,
672
+ certificate: await generateQrcode(`http://${ip}:7601`)
673
+ }))
674
+ );
675
+ const table = new import_console_table_printer.Table({
676
+ columns: [
677
+ { name: "target", alignment: "left" },
678
+ { name: "certificate", alignment: "center", minLen: 28 }
679
+ ]
680
+ });
681
+ ipTable.forEach((ip) => {
682
+ table.addRow(ip);
683
+ });
684
+ table.printTable();
685
+ consola.info(`2. Set proxy on mobile device (Available IPs: ${ips}):${import_picocolors2.default.bold(7600)}
686
+
687
+ `);
688
+ }
689
+ }
620
690
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
621
691
  _printUrls == null ? void 0 : _printUrls();
622
692
  if (caddy)
@@ -625,9 +695,9 @@ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
625
695
  caddy.run(source, target, {
626
696
  base,
627
697
  ...options
628
- }).then(() => {
629
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
630
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
698
+ }).then(async () => {
699
+ await printForwardProxy();
700
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
631
701
  }).catch((e) => {
632
702
  throw e;
633
703
  });
@@ -657,6 +727,10 @@ var unpluginFactory = (options) => ({
657
727
  consola.fail("please provide target");
658
728
  return;
659
729
  }
730
+ if (target.match(/^(?:https?)?:\/\//)) {
731
+ consola.fail("target must be a domain");
732
+ return;
733
+ }
660
734
  const _printUrls = server.printUrls.bind(server);
661
735
  let source = `localhost:${config.server.port || 5173}`;
662
736
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
@@ -686,6 +760,10 @@ var unpluginFactory = (options) => ({
686
760
  consola.fail("please provide target");
687
761
  return;
688
762
  }
763
+ if (target.match(/^(?:https?)?:\/\//)) {
764
+ consola.fail("target must be a domain");
765
+ return;
766
+ }
689
767
  const devServer = {
690
768
  host: "localhost",
691
769
  port: 8080,
@@ -710,9 +788,9 @@ var unpluginFactory = (options) => ({
710
788
  caddy.run(source, target, {
711
789
  ...options
712
790
  }).then(() => {
713
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
714
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
715
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
791
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
792
+ await printForwardProxy();
793
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
716
794
  });
717
795
  }).catch((e) => {
718
796
  throw e;
@@ -736,6 +814,10 @@ var unpluginFactory = (options) => ({
736
814
  consola.fail("please provide target");
737
815
  return;
738
816
  }
817
+ if (target.match(/^(?:https?)?:\/\//)) {
818
+ consola.fail("target must be a domain");
819
+ return;
820
+ }
739
821
  const devServer = {
740
822
  host: "localhost",
741
823
  port: 8080,
@@ -750,9 +832,9 @@ var unpluginFactory = (options) => ({
750
832
  caddy = new CaddyInstant();
751
833
  caddy.run(source, target, {
752
834
  ...options
753
- }).then(() => {
754
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
755
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
835
+ }).then(async () => {
836
+ await printForwardProxy();
837
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
756
838
  }).catch((e) => {
757
839
  throw e;
758
840
  });
package/dist/rollup.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-KVE7AVSI.js";
4
- import "./chunk-2VGRJ3QS.js";
3
+ } from "./chunk-DKHKFLLC.js";
4
+ import "./chunk-2P7SUCQ3.js";
5
5
 
6
6
  // src/rollup.ts
7
7
  import { createRollupPlugin } from "unplugin";
package/dist/rspack.cjs CHANGED
@@ -36,15 +36,38 @@ module.exports = __toCommonJS(rspack_exports);
36
36
 
37
37
  // src/index.ts
38
38
  var import_node_process5 = __toESM(require("process"), 1);
39
+ var import_console_table_printer = require("console-table-printer");
40
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
39
41
  var import_unplugin = require("unplugin");
40
- var import_picocolors = __toESM(require("picocolors"), 1);
42
+
43
+ // src/caddy/index.ts
44
+ var import_node_child_process4 = require("child_process");
45
+ var import_node_fs2 = require("fs");
46
+ var import_promises2 = require("fs/promises");
47
+ var import_node_os3 = require("os");
48
+ var import_node_path3 = require("path");
49
+ var import_node_process4 = __toESM(require("process"), 1);
50
+ var import_got_cjs = require("got-cjs");
51
+ var import_http_proxy_agent = require("http-proxy-agent");
52
+ var import_https_proxy_agent = require("https-proxy-agent");
53
+ var lockfile = __toESM(require("proper-lockfile"), 1);
54
+
55
+ // src/host/index.ts
56
+ var import_node_child_process2 = require("child_process");
57
+ var import_node_fs = require("fs");
58
+ var import_node_process2 = __toESM(require("process"), 1);
59
+ var import_node_util = require("util");
60
+ var import_hostile = __toESM(require("hostile"), 1);
41
61
 
42
62
  // src/utils.ts
43
- var import_node_process = __toESM(require("process"), 1);
44
- var import_node_path = __toESM(require("path"), 1);
45
- var import_promises = require("fs/promises");
46
63
  var import_node_child_process = require("child_process");
64
+ var import_promises = require("fs/promises");
65
+ var import_node_os = require("os");
66
+ var import_node_path = __toESM(require("path"), 1);
67
+ var import_node_process = __toESM(require("process"), 1);
47
68
  var import_consola = require("consola");
69
+ var import_picocolors = __toESM(require("picocolors"), 1);
70
+ var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
48
71
  var consola = (0, import_consola.createConsola)({
49
72
  level: 3
50
73
  }).withTag("reverse-proxy");
@@ -74,37 +97,34 @@ function isAdmin() {
74
97
  return false;
75
98
  }
76
99
  } else {
77
- return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
100
+ return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
78
101
  }
79
102
  }
80
-
81
- // src/caddy/index.ts
82
- var import_node_os2 = require("os");
83
- var import_node_process4 = __toESM(require("process"), 1);
84
- var import_node_fs2 = require("fs");
85
- var import_node_child_process4 = require("child_process");
86
- var import_promises2 = require("fs/promises");
87
- var import_got_cjs = require("got-cjs");
88
- var import_http_proxy_agent = require("http-proxy-agent");
89
- var import_https_proxy_agent = require("https-proxy-agent");
90
- var lockfile = __toESM(require("proper-lockfile"), 1);
103
+ function getIpv4List() {
104
+ const interfaces = (0, import_node_os.networkInterfaces)();
105
+ return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
106
+ (detail) => detail.address && (detail.family === "IPv4" || detail.family === 4)
107
+ ).filter((detail) => detail.family === "IPv4" && !detail.internal).map((detail) => detail.address);
108
+ }
109
+ async function generateQrcode(input) {
110
+ return new Promise((resolve) => {
111
+ import_qrcode_terminal.default.generate(input, { small: true }, (code) => {
112
+ resolve(code.split("\n").map((line) => import_picocolors.default.bgBlack(import_picocolors.default.white(line))).join("\n"));
113
+ });
114
+ });
115
+ }
91
116
 
92
117
  // src/host/index.ts
93
- var import_node_process2 = __toESM(require("process"), 1);
94
- var import_node_child_process2 = require("child_process");
95
- var import_node_fs = require("fs");
96
- var import_node_util = require("util");
97
- var import_hostile = __toESM(require("hostile"), 1);
98
118
  var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
99
119
  var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
100
120
  function getPathOfSystemHostsPath() {
101
121
  return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
102
122
  }
103
123
  async function syncHost() {
104
- return new Promise((resolve, reject) => {
124
+ return new Promise((resolve, _reject) => {
105
125
  (0, import_node_child_process2.exec)(
106
126
  import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
107
- (error, stdout, stderr) => {
127
+ (error, _stdout, _stderr) => {
108
128
  if (error) {
109
129
  consola.error(`exec error: ${error}`);
110
130
  return resolve(false);
@@ -133,8 +153,8 @@ async function removeHost(ip, host) {
133
153
  }
134
154
 
135
155
  // src/caddy/constants.ts
156
+ var import_node_os2 = __toESM(require("os"), 1);
136
157
  var import_node_path2 = require("path");
137
- var import_node_os = __toESM(require("os"), 1);
138
158
  var import_node_process3 = __toESM(require("process"), 1);
139
159
  var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
140
160
  import_dotenv_flow.default.config({
@@ -142,7 +162,7 @@ import_dotenv_flow.default.config({
142
162
  });
143
163
  function resolvePath(path2) {
144
164
  if (path2.startsWith("~"))
145
- return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
165
+ return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
146
166
  return path2;
147
167
  }
148
168
  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");
@@ -261,12 +281,12 @@ var supportList = [
261
281
  ];
262
282
 
263
283
  // src/caddy/utils.ts
264
- var import_node_net = require("net");
265
284
  var import_node_child_process3 = require("child_process");
285
+ var import_node_net = require("net");
266
286
  var import_ora = __toESM(require("ora"), 1);
267
287
  var spinner;
268
288
  function tryPort(port) {
269
- return new Promise((resolve, reject) => {
289
+ return new Promise((resolve, _reject) => {
270
290
  try {
271
291
  const server = (0, import_node_net.createServer)().listen(port);
272
292
  server.on("listening", () => {
@@ -278,14 +298,14 @@ function tryPort(port) {
278
298
  resolve(true);
279
299
  server.close();
280
300
  });
281
- } catch (e) {
301
+ } catch {
282
302
  resolve(true);
283
303
  }
284
304
  });
285
305
  }
286
306
  async function kill(port) {
287
307
  return new Promise((resolve, reject) => {
288
- (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
308
+ (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
289
309
  if (err) {
290
310
  reject(err);
291
311
  } else {
@@ -338,14 +358,14 @@ async function download() {
338
358
  (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
339
359
  }
340
360
  const file = (0, import_node_fs2.createWriteStream)(caddyPath);
341
- let _platform = (0, import_node_os2.platform)().toString();
361
+ let _platform = (0, import_node_os3.platform)().toString();
342
362
  _platform === "win32" && (_platform = "windows");
343
363
  let _arch = import_node_process4.default.arch.toString();
344
364
  _arch === "x64" && (_arch = "amd64");
345
365
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
346
366
  if (!support)
347
367
  return reject(new Error("not support"));
348
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
368
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
349
369
  (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
350
370
  const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
351
371
  const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
@@ -419,7 +439,27 @@ var CaddyInstant = class {
419
439
  debug
420
440
  auto_https disable_redirects
421
441
  }
422
-
442
+
443
+ :7601 {
444
+ root * "${(0, import_node_path3.join)(
445
+ import_node_process4.default.platform === "win32" ? `${import_node_process4.default.env.AppData}/Caddy` : `${import_node_process4.default.env.HOME}/Library/Application Support/Caddy`,
446
+ "./pki/authorities/local"
447
+ )}"
448
+ file_server browse
449
+ }
450
+
451
+ # \u6B63\u5411\u4EE3\u7406\u914D\u7F6E
452
+ :7600 {
453
+ bind 0.0.0.0
454
+
455
+ forward_proxy {
456
+ hide_ip
457
+ hide_via
458
+ acl {
459
+ allow all
460
+ }
461
+ }
462
+ }
423
463
  `;
424
464
  await (0, import_promises2.writeFile)(caddyFilePath, contet);
425
465
  this.caddyfile = contet;
@@ -437,7 +477,6 @@ var CaddyInstant = class {
437
477
  /**
438
478
  * @param source like `127.0.0.1:8080`
439
479
  * @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
440
- * @returns
441
480
  */
442
481
  async run(source, target, options) {
443
482
  source = source.replace("0.0.0.0", "127.0.0.1");
@@ -482,7 +521,6 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
482
521
  }
483
522
  }
484
523
  }
485
-
486
524
  `;
487
525
  await this.writeCaddyfile();
488
526
  }
@@ -616,6 +654,38 @@ ${line}
616
654
  var config;
617
655
  var caddy;
618
656
  var cwd = import_node_process5.default.cwd();
657
+ function colorUrl(url) {
658
+ return import_picocolors2.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
659
+ }
660
+ async function printForwardProxy() {
661
+ const ipv4List = getIpv4List();
662
+ if (ipv4List.length) {
663
+ const ips = ipv4List.map((ip) => import_picocolors2.default.cyan(ip)).join(", ");
664
+ consola.info(`${import_picocolors2.default.bold("Mobile device proxy access")}:
665
+ `);
666
+ consola.info("1. Install certificate: scan the QR code and download the `root.crt` file,");
667
+ consola.info(" then install it on your mobile device");
668
+ const ipTable = await Promise.all(
669
+ ipv4List.map(async (ip) => ({
670
+ target: `http://${ip}:7601`,
671
+ certificate: await generateQrcode(`http://${ip}:7601`)
672
+ }))
673
+ );
674
+ const table = new import_console_table_printer.Table({
675
+ columns: [
676
+ { name: "target", alignment: "left" },
677
+ { name: "certificate", alignment: "center", minLen: 28 }
678
+ ]
679
+ });
680
+ ipTable.forEach((ip) => {
681
+ table.addRow(ip);
682
+ });
683
+ table.printTable();
684
+ consola.info(`2. Set proxy on mobile device (Available IPs: ${ips}):${import_picocolors2.default.bold(7600)}
685
+
686
+ `);
687
+ }
688
+ }
619
689
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
620
690
  _printUrls == null ? void 0 : _printUrls();
621
691
  if (caddy)
@@ -624,9 +694,9 @@ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
624
694
  caddy.run(source, target, {
625
695
  base,
626
696
  ...options
627
- }).then(() => {
628
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
629
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
697
+ }).then(async () => {
698
+ await printForwardProxy();
699
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
630
700
  }).catch((e) => {
631
701
  throw e;
632
702
  });
@@ -656,6 +726,10 @@ var unpluginFactory = (options) => ({
656
726
  consola.fail("please provide target");
657
727
  return;
658
728
  }
729
+ if (target.match(/^(?:https?)?:\/\//)) {
730
+ consola.fail("target must be a domain");
731
+ return;
732
+ }
659
733
  const _printUrls = server.printUrls.bind(server);
660
734
  let source = `localhost:${config.server.port || 5173}`;
661
735
  const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
@@ -685,6 +759,10 @@ var unpluginFactory = (options) => ({
685
759
  consola.fail("please provide target");
686
760
  return;
687
761
  }
762
+ if (target.match(/^(?:https?)?:\/\//)) {
763
+ consola.fail("target must be a domain");
764
+ return;
765
+ }
688
766
  const devServer = {
689
767
  host: "localhost",
690
768
  port: 8080,
@@ -709,9 +787,9 @@ var unpluginFactory = (options) => ({
709
787
  caddy.run(source, target, {
710
788
  ...options
711
789
  }).then(() => {
712
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
713
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
714
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
790
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
791
+ await printForwardProxy();
792
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
715
793
  });
716
794
  }).catch((e) => {
717
795
  throw e;
@@ -735,6 +813,10 @@ var unpluginFactory = (options) => ({
735
813
  consola.fail("please provide target");
736
814
  return;
737
815
  }
816
+ if (target.match(/^(?:https?)?:\/\//)) {
817
+ consola.fail("target must be a domain");
818
+ return;
819
+ }
738
820
  const devServer = {
739
821
  host: "localhost",
740
822
  port: 8080,
@@ -749,9 +831,9 @@ var unpluginFactory = (options) => ({
749
831
  caddy = new CaddyInstant();
750
832
  caddy.run(source, target, {
751
833
  ...options
752
- }).then(() => {
753
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
754
- consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
834
+ }).then(async () => {
835
+ await printForwardProxy();
836
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
755
837
  }).catch((e) => {
756
838
  throw e;
757
839
  });
package/dist/rspack.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-KVE7AVSI.js";
4
- import "./chunk-2VGRJ3QS.js";
3
+ } from "./chunk-DKHKFLLC.js";
4
+ import "./chunk-2P7SUCQ3.js";
5
5
 
6
6
  // src/rspack.ts
7
7
  var rspack_default = src_default.rspack;