unplugin-https-reverse-proxy 1.0.0 → 2.0.0

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/index.cjs CHANGED
@@ -37,15 +37,38 @@ __export(src_exports, {
37
37
  });
38
38
  module.exports = __toCommonJS(src_exports);
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
  });
@@ -710,9 +780,9 @@ var unpluginFactory = (options) => ({
710
780
  caddy.run(source, target, {
711
781
  ...options
712
782
  }).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}`)}`);
783
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
784
+ await printForwardProxy();
785
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
716
786
  });
717
787
  }).catch((e) => {
718
788
  throw e;
@@ -750,9 +820,9 @@ var unpluginFactory = (options) => ({
750
820
  caddy = new CaddyInstant();
751
821
  caddy.run(source, target, {
752
822
  ...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}`)}`);
823
+ }).then(async () => {
824
+ await printForwardProxy();
825
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
756
826
  }).catch((e) => {
757
827
  throw e;
758
828
  });
package/dist/index.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  unplugin,
4
4
  unpluginFactory,
5
5
  vitePrintUrls
6
- } from "./chunk-KVE7AVSI.js";
7
- import "./chunk-2VGRJ3QS.js";
6
+ } from "./chunk-SO2FMQ2Q.js";
7
+ import "./chunk-2P7SUCQ3.js";
8
8
  export {
9
9
  src_default as default,
10
10
  unplugin,
package/dist/nuxt.cjs CHANGED
@@ -35,14 +35,41 @@ __export(nuxt_exports, {
35
35
  module.exports = __toCommonJS(nuxt_exports);
36
36
  var import_node_process6 = __toESM(require("process"), 1);
37
37
  var import_kit = require("@nuxt/kit");
38
- var import_schema = require("@nuxt/schema");
38
+
39
+ // src/index.ts
40
+ var import_node_process5 = __toESM(require("process"), 1);
41
+ var import_console_table_printer = require("console-table-printer");
42
+ var import_picocolors2 = __toESM(require("picocolors"), 1);
43
+ var import_unplugin = require("unplugin");
44
+
45
+ // src/caddy/index.ts
46
+ var import_node_child_process4 = require("child_process");
47
+ var import_node_fs2 = require("fs");
48
+ var import_promises2 = 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);
52
+ var import_got_cjs = require("got-cjs");
53
+ var import_http_proxy_agent = require("http-proxy-agent");
54
+ var import_https_proxy_agent = require("https-proxy-agent");
55
+ var lockfile = __toESM(require("proper-lockfile"), 1);
56
+
57
+ // src/host/index.ts
58
+ var import_node_child_process2 = require("child_process");
59
+ var import_node_fs = require("fs");
60
+ var import_node_process2 = __toESM(require("process"), 1);
61
+ var import_node_util = require("util");
62
+ var import_hostile = __toESM(require("hostile"), 1);
39
63
 
40
64
  // src/utils.ts
41
- var import_node_process = __toESM(require("process"), 1);
42
- var import_node_path = __toESM(require("path"), 1);
43
- var import_promises = require("fs/promises");
44
65
  var import_node_child_process = require("child_process");
66
+ var import_promises = require("fs/promises");
67
+ var import_node_os = require("os");
68
+ var import_node_path = __toESM(require("path"), 1);
69
+ var import_node_process = __toESM(require("process"), 1);
45
70
  var import_consola = require("consola");
71
+ var import_picocolors = __toESM(require("picocolors"), 1);
72
+ var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
46
73
  var consola = (0, import_consola.createConsola)({
47
74
  level: 3
48
75
  }).withTag("reverse-proxy");
@@ -72,42 +99,34 @@ function isAdmin() {
72
99
  return false;
73
100
  }
74
101
  } else {
75
- return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
102
+ return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
76
103
  }
77
104
  }
78
-
79
- // src/index.ts
80
- var import_node_process5 = __toESM(require("process"), 1);
81
- var import_unplugin = require("unplugin");
82
- var import_picocolors = __toESM(require("picocolors"), 1);
83
-
84
- // src/caddy/index.ts
85
- var import_node_os2 = require("os");
86
- var import_node_process4 = __toESM(require("process"), 1);
87
- var import_node_fs2 = require("fs");
88
- var import_node_child_process4 = require("child_process");
89
- var import_promises2 = require("fs/promises");
90
- var import_got_cjs = require("got-cjs");
91
- var import_http_proxy_agent = require("http-proxy-agent");
92
- var import_https_proxy_agent = require("https-proxy-agent");
93
- var lockfile = __toESM(require("proper-lockfile"), 1);
105
+ function getIpv4List() {
106
+ const interfaces = (0, import_node_os.networkInterfaces)();
107
+ return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
108
+ (detail) => detail.address && (detail.family === "IPv4" || detail.family === 4)
109
+ ).filter((detail) => detail.family === "IPv4" && !detail.internal).map((detail) => detail.address);
110
+ }
111
+ async function generateQrcode(input) {
112
+ return new Promise((resolve) => {
113
+ import_qrcode_terminal.default.generate(input, { small: true }, (code) => {
114
+ resolve(code.split("\n").map((line) => import_picocolors.default.bgBlack(import_picocolors.default.white(line))).join("\n"));
115
+ });
116
+ });
117
+ }
94
118
 
95
119
  // src/host/index.ts
96
- var import_node_process2 = __toESM(require("process"), 1);
97
- var import_node_child_process2 = require("child_process");
98
- var import_node_fs = require("fs");
99
- var import_node_util = require("util");
100
- var import_hostile = __toESM(require("hostile"), 1);
101
120
  var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
102
121
  var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
103
122
  function getPathOfSystemHostsPath() {
104
123
  return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
105
124
  }
106
125
  async function syncHost() {
107
- return new Promise((resolve, reject) => {
126
+ return new Promise((resolve, _reject) => {
108
127
  (0, import_node_child_process2.exec)(
109
128
  import_node_process2.default.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
110
- (error, stdout, stderr) => {
129
+ (error, _stdout, _stderr) => {
111
130
  if (error) {
112
131
  consola.error(`exec error: ${error}`);
113
132
  return resolve(false);
@@ -136,8 +155,8 @@ async function removeHost(ip, host) {
136
155
  }
137
156
 
138
157
  // src/caddy/constants.ts
158
+ var import_node_os2 = __toESM(require("os"), 1);
139
159
  var import_node_path2 = require("path");
140
- var import_node_os = __toESM(require("os"), 1);
141
160
  var import_node_process3 = __toESM(require("process"), 1);
142
161
  var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
143
162
  import_dotenv_flow.default.config({
@@ -145,7 +164,7 @@ import_dotenv_flow.default.config({
145
164
  });
146
165
  function resolvePath(path2) {
147
166
  if (path2.startsWith("~"))
148
- return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
167
+ return (0, import_node_path2.join)(import_node_os2.default.homedir() || "", path2.slice(1));
149
168
  return path2;
150
169
  }
151
170
  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");
@@ -264,12 +283,12 @@ var supportList = [
264
283
  ];
265
284
 
266
285
  // src/caddy/utils.ts
267
- var import_node_net = require("net");
268
286
  var import_node_child_process3 = require("child_process");
287
+ var import_node_net = require("net");
269
288
  var import_ora = __toESM(require("ora"), 1);
270
289
  var spinner;
271
290
  function tryPort(port) {
272
- return new Promise((resolve, reject) => {
291
+ return new Promise((resolve, _reject) => {
273
292
  try {
274
293
  const server = (0, import_node_net.createServer)().listen(port);
275
294
  server.on("listening", () => {
@@ -281,14 +300,14 @@ function tryPort(port) {
281
300
  resolve(true);
282
301
  server.close();
283
302
  });
284
- } catch (e) {
303
+ } catch {
285
304
  resolve(true);
286
305
  }
287
306
  });
288
307
  }
289
308
  async function kill(port) {
290
309
  return new Promise((resolve, reject) => {
291
- (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
310
+ (0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
292
311
  if (err) {
293
312
  reject(err);
294
313
  } else {
@@ -341,14 +360,14 @@ async function download() {
341
360
  (0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
342
361
  }
343
362
  const file = (0, import_node_fs2.createWriteStream)(caddyPath);
344
- let _platform = (0, import_node_os2.platform)().toString();
363
+ let _platform = (0, import_node_os3.platform)().toString();
345
364
  _platform === "win32" && (_platform = "windows");
346
365
  let _arch = import_node_process4.default.arch.toString();
347
366
  _arch === "x64" && (_arch = "amd64");
348
367
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
349
368
  if (!support)
350
369
  return reject(new Error("not support"));
351
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
370
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
352
371
  (0, import_node_fs2.existsSync)(caddyPath) && (0, import_node_fs2.unlinkSync)(caddyPath);
353
372
  const httpProxy = import_node_process4.default.env.HTTP_PROXY || import_node_process4.default.env.http_proxy;
354
373
  const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
@@ -422,7 +441,27 @@ var CaddyInstant = class {
422
441
  debug
423
442
  auto_https disable_redirects
424
443
  }
425
-
444
+
445
+ :7601 {
446
+ root * "${(0, import_node_path3.join)(
447
+ import_node_process4.default.platform === "win32" ? `${import_node_process4.default.env.AppData}/Caddy` : `${import_node_process4.default.env.HOME}/Library/Application Support/Caddy`,
448
+ "./pki/authorities/local"
449
+ )}"
450
+ file_server browse
451
+ }
452
+
453
+ # \u6B63\u5411\u4EE3\u7406\u914D\u7F6E
454
+ :7600 {
455
+ bind 0.0.0.0
456
+
457
+ forward_proxy {
458
+ hide_ip
459
+ hide_via
460
+ acl {
461
+ allow all
462
+ }
463
+ }
464
+ }
426
465
  `;
427
466
  await (0, import_promises2.writeFile)(caddyFilePath, contet);
428
467
  this.caddyfile = contet;
@@ -440,7 +479,6 @@ var CaddyInstant = class {
440
479
  /**
441
480
  * @param source like `127.0.0.1:8080`
442
481
  * @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
443
- * @returns
444
482
  */
445
483
  async run(source, target, options) {
446
484
  source = source.replace("0.0.0.0", "127.0.0.1");
@@ -485,7 +523,6 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
485
523
  }
486
524
  }
487
525
  }
488
-
489
526
  `;
490
527
  await this.writeCaddyfile();
491
528
  }
@@ -618,6 +655,38 @@ ${line}
618
655
  // src/index.ts
619
656
  var caddy;
620
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
+ }
621
690
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
622
691
  _printUrls == null ? void 0 : _printUrls();
623
692
  if (caddy)
@@ -626,15 +695,16 @@ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
626
695
  caddy.run(source, target, {
627
696
  base,
628
697
  ...options
629
- }).then(() => {
630
- const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
631
- 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}`)}`);
632
701
  }).catch((e) => {
633
702
  throw e;
634
703
  });
635
704
  });
636
705
 
637
706
  // src/nuxt.ts
707
+ var import_schema = require("@nuxt/schema");
638
708
  var nuxt_default = (0, import_kit.defineNuxtModule)({
639
709
  meta: {
640
710
  name: "nuxt-unplugin-https-reverse-proxy",
package/dist/nuxt.d.cts CHANGED
@@ -3,6 +3,6 @@ import { Options } from './types.cjs';
3
3
 
4
4
  interface ModuleOptions extends Options {
5
5
  }
6
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
6
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
7
 
8
8
  export { type ModuleOptions, _default as default };
package/dist/nuxt.d.ts CHANGED
@@ -3,6 +3,6 @@ import { Options } from './types.js';
3
3
 
4
4
  interface ModuleOptions extends Options {
5
5
  }
6
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
6
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
7
 
8
8
  export { type ModuleOptions, _default as default };
package/dist/nuxt.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  vitePrintUrls
3
- } from "./chunk-KVE7AVSI.js";
3
+ } from "./chunk-SO2FMQ2Q.js";
4
4
  import {
5
5
  consola,
6
6
  isAdmin
7
- } from "./chunk-2VGRJ3QS.js";
7
+ } from "./chunk-2P7SUCQ3.js";
8
8
 
9
9
  // src/nuxt.ts
10
10
  import process from "node:process";