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/utils.d.ts
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 };
|
package/dist/utils.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chmodRecursive,
|
|
3
3
|
consola,
|
|
4
|
+
generateQrcode,
|
|
5
|
+
getIpv4List,
|
|
4
6
|
isAdmin,
|
|
5
7
|
once
|
|
6
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-2P7SUCQ3.js";
|
|
7
9
|
export {
|
|
8
10
|
chmodRecursive,
|
|
9
11
|
consola,
|
|
12
|
+
generateQrcode,
|
|
13
|
+
getIpv4List,
|
|
10
14
|
isAdmin,
|
|
11
15
|
once
|
|
12
16
|
};
|
package/dist/vite.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/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/dist/webpack.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
|
});
|