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/README.md CHANGED
@@ -6,7 +6,6 @@ A plugin for https reverse proxy, support `vite`、`webpack` and `rspack`.
6
6
 
7
7
  ## Install
8
8
 
9
-
10
9
  Support set caddy file path by environment variable `UHRP_CADDY_PATH`, default is system cache folder.
11
10
 
12
11
  ```env
@@ -14,7 +13,6 @@ Support set caddy file path by environment variable `UHRP_CADDY_PATH`, default i
14
13
  UHRP_CADDY_PATH=~/tmp/.uhrp
15
14
  ```
16
15
 
17
-
18
16
  ```bash
19
17
  # not auto install caddy when postinstall
20
18
  npm i unplugin-https-reverse-proxy --save-dev
@@ -306,6 +304,12 @@ module.exports = {
306
304
 
307
305
  <br></details>
308
306
 
307
+ ## NOTICE!
308
+ You need delete `caddy` executable file after you updated to `^2.0.0`.
309
+ The default path is `$TMPDIR/caddy`, and if you set `UHRP_CADDY_PATH`, it will be in the path you set.
310
+
311
+ Please check [caddy path](https://github.com/zcf0508/unplugin-https-reverse-proxy/blob/v1.0.0/src/caddy/constants.ts#L17).
312
+
309
313
  ## Usage
310
314
 
311
315
  ```bash
@@ -1,9 +1,12 @@
1
1
  // src/utils.ts
2
- import process from "node:process";
3
- import path from "node:path";
4
- import { chmod, readdir, stat } from "node:fs/promises";
5
2
  import { execSync } from "node:child_process";
3
+ import { chmod, readdir, stat } from "node:fs/promises";
4
+ import { networkInterfaces } from "node:os";
5
+ import path from "node:path";
6
+ import process from "node:process";
6
7
  import { createConsola } from "consola";
8
+ import c from "picocolors";
9
+ import qrcode from "qrcode-terminal";
7
10
  var consola = createConsola({
8
11
  level: 3
9
12
  }).withTag("reverse-proxy");
@@ -33,13 +36,28 @@ function isAdmin() {
33
36
  return false;
34
37
  }
35
38
  } else {
36
- return process.getuid && process.getuid() === 0;
39
+ return !!(process.getuid && process.getuid() === 0);
37
40
  }
38
41
  }
42
+ function getIpv4List() {
43
+ const interfaces = networkInterfaces();
44
+ return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
45
+ (detail) => detail.address && (detail.family === "IPv4" || detail.family === 4)
46
+ ).filter((detail) => detail.family === "IPv4" && !detail.internal).map((detail) => detail.address);
47
+ }
48
+ async function generateQrcode(input) {
49
+ return new Promise((resolve) => {
50
+ qrcode.generate(input, { small: true }, (code) => {
51
+ resolve(code.split("\n").map((line) => c.bgBlack(c.white(line))).join("\n"));
52
+ });
53
+ });
54
+ }
39
55
 
40
56
  export {
41
57
  consola,
42
58
  chmodRecursive,
43
59
  once,
44
- isAdmin
60
+ isAdmin,
61
+ getIpv4List,
62
+ generateQrcode
45
63
  };
@@ -1,30 +1,34 @@
1
1
  import {
2
2
  chmodRecursive,
3
3
  consola,
4
+ generateQrcode,
5
+ getIpv4List,
4
6
  isAdmin,
5
7
  once
6
- } from "./chunk-2VGRJ3QS.js";
8
+ } from "./chunk-2P7SUCQ3.js";
7
9
 
8
10
  // src/index.ts
9
11
  import process4 from "node:process";
10
- import { createUnplugin } from "unplugin";
12
+ import { Table } from "console-table-printer";
11
13
  import c from "picocolors";
14
+ import { createUnplugin } from "unplugin";
12
15
 
13
16
  // src/caddy/index.ts
14
- import { platform } from "node:os";
15
- import process3 from "node:process";
16
- import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
17
17
  import { spawn } from "node:child_process";
18
+ import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
18
19
  import { readFile, unlink, writeFile } from "node:fs/promises";
20
+ import { platform } from "node:os";
21
+ import { join as join2 } from "node:path";
22
+ import process3 from "node:process";
19
23
  import { got } from "got-cjs";
20
24
  import { HttpProxyAgent } from "http-proxy-agent";
21
25
  import { HttpsProxyAgent } from "https-proxy-agent";
22
26
  import * as lockfile from "proper-lockfile";
23
27
 
24
28
  // src/host/index.ts
25
- import process from "node:process";
26
29
  import { exec } from "node:child_process";
27
30
  import { chmodSync } from "node:fs";
31
+ import process from "node:process";
28
32
  import { promisify } from "node:util";
29
33
  import hostile from "hostile";
30
34
  var _setHost = promisify(hostile.set);
@@ -33,10 +37,10 @@ function getPathOfSystemHostsPath() {
33
37
  return process.platform === "win32" ? `${process.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
34
38
  }
35
39
  async function syncHost() {
36
- return new Promise((resolve, reject) => {
40
+ return new Promise((resolve, _reject) => {
37
41
  exec(
38
42
  process.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
39
- (error, stdout, stderr) => {
43
+ (error, _stdout, _stderr) => {
40
44
  if (error) {
41
45
  consola.error(`exec error: ${error}`);
42
46
  return resolve(false);
@@ -65,8 +69,8 @@ async function removeHost(ip, host) {
65
69
  }
66
70
 
67
71
  // src/caddy/constants.ts
68
- import { join } from "node:path";
69
72
  import os from "node:os";
73
+ import { join } from "node:path";
70
74
  import process2 from "node:process";
71
75
  import dotenvFlow from "dotenv-flow";
72
76
  dotenvFlow.config({
@@ -193,12 +197,12 @@ var supportList = [
193
197
  ];
194
198
 
195
199
  // src/caddy/utils.ts
196
- import { createServer } from "node:net";
197
200
  import { exec as exec2 } from "node:child_process";
201
+ import { createServer } from "node:net";
198
202
  import ora from "ora";
199
203
  var spinner;
200
204
  function tryPort(port) {
201
- return new Promise((resolve, reject) => {
205
+ return new Promise((resolve, _reject) => {
202
206
  try {
203
207
  const server = createServer().listen(port);
204
208
  server.on("listening", () => {
@@ -210,14 +214,14 @@ function tryPort(port) {
210
214
  resolve(true);
211
215
  server.close();
212
216
  });
213
- } catch (e) {
217
+ } catch {
214
218
  resolve(true);
215
219
  }
216
220
  });
217
221
  }
218
222
  async function kill(port) {
219
223
  return new Promise((resolve, reject) => {
220
- exec2(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
224
+ exec2(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
221
225
  if (err) {
222
226
  reject(err);
223
227
  } else {
@@ -277,7 +281,7 @@ async function download() {
277
281
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
278
282
  if (!support)
279
283
  return reject(new Error("not support"));
280
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
284
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
281
285
  existsSync(caddyPath) && unlinkSync(caddyPath);
282
286
  const httpProxy = process3.env.HTTP_PROXY || process3.env.http_proxy;
283
287
  const httpsProxy = process3.env.HTTPS_PROXY || process3.env.https_proxy;
@@ -351,7 +355,27 @@ var CaddyInstant = class {
351
355
  debug
352
356
  auto_https disable_redirects
353
357
  }
354
-
358
+
359
+ :7601 {
360
+ root * "${join2(
361
+ process3.platform === "win32" ? `${process3.env.AppData}/Caddy` : `${process3.env.HOME}/Library/Application Support/Caddy`,
362
+ "./pki/authorities/local"
363
+ )}"
364
+ file_server browse
365
+ }
366
+
367
+ # \u6B63\u5411\u4EE3\u7406\u914D\u7F6E
368
+ :7600 {
369
+ bind 0.0.0.0
370
+
371
+ forward_proxy {
372
+ hide_ip
373
+ hide_via
374
+ acl {
375
+ allow all
376
+ }
377
+ }
378
+ }
355
379
  `;
356
380
  await writeFile(caddyFilePath, contet);
357
381
  this.caddyfile = contet;
@@ -369,7 +393,6 @@ var CaddyInstant = class {
369
393
  /**
370
394
  * @param source like `127.0.0.1:8080`
371
395
  * @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
372
- * @returns
373
396
  */
374
397
  async run(source, target, options) {
375
398
  source = source.replace("0.0.0.0", "127.0.0.1");
@@ -414,7 +437,6 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
414
437
  }
415
438
  }
416
439
  }
417
-
418
440
  `;
419
441
  await this.writeCaddyfile();
420
442
  }
@@ -548,6 +570,38 @@ ${line}
548
570
  var config;
549
571
  var caddy;
550
572
  var cwd = process4.cwd();
573
+ function colorUrl(url) {
574
+ return c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
575
+ }
576
+ async function printForwardProxy() {
577
+ const ipv4List = getIpv4List();
578
+ if (ipv4List.length) {
579
+ const ips = ipv4List.map((ip) => c.cyan(ip)).join(", ");
580
+ consola.info(`${c.bold("Mobile device proxy access")}:
581
+ `);
582
+ consola.info("1. Install certificate: scan the QR code and download the `root.crt` file,");
583
+ consola.info(" then install it on your mobile device");
584
+ const ipTable = await Promise.all(
585
+ ipv4List.map(async (ip) => ({
586
+ target: `http://${ip}:7601`,
587
+ certificate: await generateQrcode(`http://${ip}:7601`)
588
+ }))
589
+ );
590
+ const table = new Table({
591
+ columns: [
592
+ { name: "target", alignment: "left" },
593
+ { name: "certificate", alignment: "center", minLen: 28 }
594
+ ]
595
+ });
596
+ ipTable.forEach((ip) => {
597
+ table.addRow(ip);
598
+ });
599
+ table.printTable();
600
+ consola.info(`2. Set proxy on mobile device (Available IPs: ${ips}):${c.bold(7600)}
601
+
602
+ `);
603
+ }
604
+ }
551
605
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
552
606
  _printUrls == null ? void 0 : _printUrls();
553
607
  if (caddy)
@@ -556,8 +610,8 @@ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
556
610
  caddy.run(source, target, {
557
611
  base,
558
612
  ...options
559
- }).then(() => {
560
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
613
+ }).then(async () => {
614
+ await printForwardProxy();
561
615
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
562
616
  }).catch((e) => {
563
617
  throw e;
@@ -641,8 +695,8 @@ var unpluginFactory = (options) => ({
641
695
  caddy.run(source, target, {
642
696
  ...options
643
697
  }).then(() => {
644
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
645
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
698
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
699
+ await printForwardProxy();
646
700
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
647
701
  });
648
702
  }).catch((e) => {
@@ -681,8 +735,8 @@ var unpluginFactory = (options) => ({
681
735
  caddy = new CaddyInstant();
682
736
  caddy.run(source, target, {
683
737
  ...options
684
- }).then(() => {
685
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
738
+ }).then(async () => {
739
+ await printForwardProxy();
686
740
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
687
741
  }).catch((e) => {
688
742
  throw e;
package/dist/esbuild.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
  });
@@ -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/esbuild.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-SO2FMQ2Q.js";
4
+ import "./chunk-2P7SUCQ3.js";
5
5
 
6
6
  // src/esbuild.ts
7
7
  import { createEsbuildPlugin } from "unplugin";