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 +6 -2
- package/dist/{chunk-2VGRJ3QS.js → chunk-2P7SUCQ3.js} +23 -5
- package/dist/{chunk-KVE7AVSI.js → chunk-SO2FMQ2Q.js} +77 -23
- package/dist/esbuild.cjs +113 -43
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +113 -43
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +112 -42
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/nuxt.js +2 -2
- package/dist/rollup.cjs +113 -43
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +113 -43
- package/dist/rspack.js +2 -2
- package/dist/utils.cjs +24 -4
- package/dist/utils.d.cts +6 -4
- package/dist/utils.d.ts +6 -4
- package/dist/utils.js +5 -1
- package/dist/vite.cjs +113 -43
- package/dist/vite.d.cts +2 -1
- package/dist/vite.d.ts +2 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +113 -43
- package/dist/webpack.js +2 -2
- package/package.json +29 -26
- package/scripts/postinstall.cjs +30 -24
- package/src/caddy/constants.ts +2 -2
- package/src/caddy/index.ts +41 -20
- package/src/caddy/utils.ts +9 -9
- package/src/host/index.ts +9 -8
- package/src/index.ts +48 -10
- package/src/nuxt.ts +3 -3
- package/src/utils.ts +33 -6
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
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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,
|
|
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,
|
|
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)(
|
|
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,
|
|
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
|
|
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,
|
|
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,
|
|
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
|
-
|
|
630
|
-
consola.success(` ${
|
|
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
|
-
|
|
714
|
-
|
|
715
|
-
consola.success(` ${
|
|
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
|
-
|
|
755
|
-
consola.success(` ${
|
|
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/rollup.js
CHANGED
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
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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,
|
|
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,
|
|
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)(
|
|
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,
|
|
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
|
|
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,
|
|
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,
|
|
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
|
-
|
|
629
|
-
consola.success(` ${
|
|
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
|
});
|
|
@@ -709,9 +779,9 @@ var unpluginFactory = (options) => ({
|
|
|
709
779
|
caddy.run(source, target, {
|
|
710
780
|
...options
|
|
711
781
|
}).then(() => {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
consola.success(` ${
|
|
782
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
|
|
783
|
+
await printForwardProxy();
|
|
784
|
+
consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
715
785
|
});
|
|
716
786
|
}).catch((e) => {
|
|
717
787
|
throw e;
|
|
@@ -749,9 +819,9 @@ var unpluginFactory = (options) => ({
|
|
|
749
819
|
caddy = new CaddyInstant();
|
|
750
820
|
caddy.run(source, target, {
|
|
751
821
|
...options
|
|
752
|
-
}).then(() => {
|
|
753
|
-
|
|
754
|
-
consola.success(` ${
|
|
822
|
+
}).then(async () => {
|
|
823
|
+
await printForwardProxy();
|
|
824
|
+
consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
755
825
|
}).catch((e) => {
|
|
756
826
|
throw e;
|
|
757
827
|
});
|
package/dist/rspack.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -32,15 +32,20 @@ var utils_exports = {};
|
|
|
32
32
|
__export(utils_exports, {
|
|
33
33
|
chmodRecursive: () => chmodRecursive,
|
|
34
34
|
consola: () => consola,
|
|
35
|
+
generateQrcode: () => generateQrcode,
|
|
36
|
+
getIpv4List: () => getIpv4List,
|
|
35
37
|
isAdmin: () => isAdmin,
|
|
36
38
|
once: () => once
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(utils_exports);
|
|
39
|
-
var import_node_process = __toESM(require("process"), 1);
|
|
40
|
-
var import_node_path = __toESM(require("path"), 1);
|
|
41
|
-
var import_promises = require("fs/promises");
|
|
42
41
|
var import_node_child_process = require("child_process");
|
|
42
|
+
var import_promises = require("fs/promises");
|
|
43
|
+
var import_node_os = require("os");
|
|
44
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
45
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
43
46
|
var import_consola = require("consola");
|
|
47
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
48
|
+
var import_qrcode_terminal = __toESM(require("qrcode-terminal"), 1);
|
|
44
49
|
var consola = (0, import_consola.createConsola)({
|
|
45
50
|
level: 3
|
|
46
51
|
}).withTag("reverse-proxy");
|
|
@@ -70,13 +75,28 @@ function isAdmin() {
|
|
|
70
75
|
return false;
|
|
71
76
|
}
|
|
72
77
|
} else {
|
|
73
|
-
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
78
|
+
return !!(import_node_process.default.getuid && import_node_process.default.getuid() === 0);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
81
|
+
function getIpv4List() {
|
|
82
|
+
const interfaces = (0, import_node_os.networkInterfaces)();
|
|
83
|
+
return Object.values(interfaces).flatMap((nInterface) => nInterface ?? []).filter(
|
|
84
|
+
(detail) => detail.address && (detail.family === "IPv4" || detail.family === 4)
|
|
85
|
+
).filter((detail) => detail.family === "IPv4" && !detail.internal).map((detail) => detail.address);
|
|
86
|
+
}
|
|
87
|
+
async function generateQrcode(input) {
|
|
88
|
+
return new Promise((resolve) => {
|
|
89
|
+
import_qrcode_terminal.default.generate(input, { small: true }, (code) => {
|
|
90
|
+
resolve(code.split("\n").map((line) => import_picocolors.default.bgBlack(import_picocolors.default.white(line))).join("\n"));
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
76
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
77
95
|
0 && (module.exports = {
|
|
78
96
|
chmodRecursive,
|
|
79
97
|
consola,
|
|
98
|
+
generateQrcode,
|
|
99
|
+
getIpv4List,
|
|
80
100
|
isAdmin,
|
|
81
101
|
once
|
|
82
102
|
});
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _consola from 'consola';
|
|
2
2
|
|
|
3
|
-
declare const consola:
|
|
3
|
+
declare const consola: _consola.ConsolaInstance;
|
|
4
4
|
declare function chmodRecursive(_path: string, mode: number): Promise<void>;
|
|
5
5
|
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
6
|
-
declare function isAdmin(): boolean
|
|
6
|
+
declare function isAdmin(): boolean;
|
|
7
|
+
declare function getIpv4List(): string[];
|
|
8
|
+
declare function generateQrcode(input: string): Promise<string>;
|
|
7
9
|
|
|
8
|
-
export { chmodRecursive, consola, isAdmin, once };
|
|
10
|
+
export { chmodRecursive, consola, generateQrcode, getIpv4List, isAdmin, once };
|