unplugin-https-reverse-proxy 1.0.0-beta.9 → 1.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 +11 -1
- package/dist/chunk-2VGRJ3QS.js +45 -0
- package/dist/{chunk-ZSHTX2B6.js → chunk-KVE7AVSI.js} +259 -124
- package/dist/esbuild.cjs +250 -128
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +250 -128
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +223 -110
- package/dist/nuxt.js +7 -7
- package/dist/rollup.cjs +250 -128
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +250 -128
- package/dist/rspack.js +2 -2
- package/dist/types.cjs +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/dist/vite.cjs +250 -128
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +250 -128
- package/dist/webpack.js +2 -2
- package/package.json +11 -8
- package/scripts/postinstall.cjs +308 -0
- package/src/caddy/constants.ts +1 -0
- package/src/caddy/index.ts +225 -94
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
- package/src/index.ts +20 -15
- package/src/nuxt.ts +7 -5
- package/dist/chunk-RUJE3YFB.js +0 -63
- package/scripts/postinstall.ts +0 -19
package/dist/index.cjs
CHANGED
|
@@ -3,22 +3,8 @@ var __create = Object.create;
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
8
|
var __export = (target, all) => {
|
|
23
9
|
for (var name in all)
|
|
24
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -85,7 +71,7 @@ function isAdmin() {
|
|
|
85
71
|
try {
|
|
86
72
|
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
87
73
|
return true;
|
|
88
|
-
} catch
|
|
74
|
+
} catch {
|
|
89
75
|
return false;
|
|
90
76
|
}
|
|
91
77
|
} else {
|
|
@@ -97,22 +83,21 @@ function isAdmin() {
|
|
|
97
83
|
var import_node_os2 = require("os");
|
|
98
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
99
85
|
var import_node_fs2 = require("fs");
|
|
100
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
|
+
var import_promises2 = require("fs/promises");
|
|
101
88
|
var import_got_cjs = require("got-cjs");
|
|
102
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
103
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
104
|
-
var
|
|
91
|
+
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
105
92
|
|
|
106
93
|
// src/host/index.ts
|
|
107
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
108
95
|
var import_node_child_process2 = require("child_process");
|
|
109
96
|
var import_node_fs = require("fs");
|
|
110
|
-
var
|
|
111
|
-
var
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
115
|
-
});
|
|
97
|
+
var import_node_util = require("util");
|
|
98
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
99
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
100
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
116
101
|
function getPathOfSystemHostsPath() {
|
|
117
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
118
103
|
}
|
|
@@ -133,20 +118,18 @@ async function syncHost() {
|
|
|
133
118
|
async function addHost(ip, host) {
|
|
134
119
|
if (import_node_process2.default.platform !== "win32")
|
|
135
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
138
123
|
if (ip === "localhost")
|
|
139
|
-
|
|
140
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
141
125
|
return await syncHost();
|
|
142
126
|
}
|
|
143
127
|
async function removeHost(ip, host) {
|
|
144
128
|
if (import_node_process2.default.platform !== "win32")
|
|
145
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
146
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
147
131
|
if (ip === "localhost")
|
|
148
|
-
|
|
149
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
150
133
|
return await syncHost();
|
|
151
134
|
}
|
|
152
135
|
|
|
@@ -166,6 +149,7 @@ function resolvePath(path2) {
|
|
|
166
149
|
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");
|
|
167
150
|
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
168
151
|
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
152
|
+
var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
|
|
169
153
|
var supportList = [
|
|
170
154
|
{
|
|
171
155
|
platform: "dragonfly",
|
|
@@ -279,6 +263,7 @@ var supportList = [
|
|
|
279
263
|
|
|
280
264
|
// src/caddy/utils.ts
|
|
281
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
282
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
283
268
|
var spinner;
|
|
284
269
|
function tryPort(port) {
|
|
@@ -299,6 +284,18 @@ function tryPort(port) {
|
|
|
299
284
|
}
|
|
300
285
|
});
|
|
301
286
|
}
|
|
287
|
+
async function kill(port) {
|
|
288
|
+
return new Promise((resolve, reject) => {
|
|
289
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
290
|
+
if (err) {
|
|
291
|
+
reject(err);
|
|
292
|
+
} else {
|
|
293
|
+
consola.log(stdout);
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
302
299
|
function getNumber(number) {
|
|
303
300
|
if (number <= 0)
|
|
304
301
|
return "0%";
|
|
@@ -382,7 +379,7 @@ function testCaddy() {
|
|
|
382
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
383
380
|
return resolve(false);
|
|
384
381
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
385
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
382
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
386
383
|
child.on("close", () => {
|
|
387
384
|
return resolve(false);
|
|
388
385
|
});
|
|
@@ -398,9 +395,41 @@ var CaddyInstant = class {
|
|
|
398
395
|
constructor() {
|
|
399
396
|
this.inited = false;
|
|
400
397
|
this.stoped = false;
|
|
401
|
-
|
|
398
|
+
/** has locked */
|
|
399
|
+
this.locked = false;
|
|
400
|
+
testCaddy().then(async () => {
|
|
401
|
+
await this.getCaddyfile();
|
|
402
402
|
this.inited = true;
|
|
403
403
|
});
|
|
404
|
+
this.locked = this.checkLock();
|
|
405
|
+
}
|
|
406
|
+
checkLock() {
|
|
407
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
408
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
409
|
+
return lockfile.checkSync(caddyLockFilePath);
|
|
410
|
+
}
|
|
411
|
+
async getCaddyfile() {
|
|
412
|
+
if (!(0, import_node_fs2.existsSync)(caddyFilePath))
|
|
413
|
+
await this.initCaddyfile();
|
|
414
|
+
this.caddyfile = await (0, import_promises2.readFile)(caddyFilePath, "utf-8");
|
|
415
|
+
return this.caddyfile;
|
|
416
|
+
}
|
|
417
|
+
async initCaddyfile() {
|
|
418
|
+
const contet = `
|
|
419
|
+
{
|
|
420
|
+
debug
|
|
421
|
+
auto_https disable_redirects
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
`;
|
|
425
|
+
await (0, import_promises2.writeFile)(caddyFilePath, contet);
|
|
426
|
+
this.caddyfile = contet;
|
|
427
|
+
}
|
|
428
|
+
async writeCaddyfile() {
|
|
429
|
+
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
|
430
|
+
}
|
|
431
|
+
async deleteCaddyfile() {
|
|
432
|
+
return await (0, import_promises2.unlink)(caddyFilePath);
|
|
404
433
|
}
|
|
405
434
|
async init() {
|
|
406
435
|
await download();
|
|
@@ -419,86 +448,169 @@ var CaddyInstant = class {
|
|
|
419
448
|
showCaddyLog = false,
|
|
420
449
|
https = false
|
|
421
450
|
} = options || {};
|
|
451
|
+
this._source = source;
|
|
452
|
+
this._target = target;
|
|
422
453
|
if (!this.inited)
|
|
423
454
|
await this.init();
|
|
424
|
-
if (https && await tryPort(443))
|
|
425
|
-
await (0, import_kill_port.default)(443, "tcp");
|
|
426
|
-
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
427
|
-
await (0, import_kill_port.default)(80, "tcp");
|
|
428
455
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
429
456
|
throw new Error("update host failed");
|
|
430
457
|
consola.success("update host success\n");
|
|
458
|
+
await this.getCaddyfile();
|
|
459
|
+
if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
|
|
460
|
+
this.caddyfile = `${this.caddyfile}
|
|
461
|
+
${target.split(":")[0]}${https ? "" : ":80"} {
|
|
462
|
+
${https ? "tls internal" : ""}
|
|
463
|
+
reverse_proxy http://${source} {
|
|
464
|
+
health_uri ${base}
|
|
465
|
+
health_interval 2s
|
|
466
|
+
health_timeout 5s
|
|
467
|
+
fail_duration 2s
|
|
468
|
+
unhealthy_status 502 503 504 404
|
|
469
|
+
lb_try_duration 3s
|
|
470
|
+
lb_try_interval 300ms
|
|
471
|
+
health_headers {
|
|
472
|
+
Accept text/html
|
|
473
|
+
Accept-Encoding gzip, deflate, br
|
|
474
|
+
User-Agent Caddy-Health-Check
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
@error status 502 503 504 404
|
|
478
|
+
handle_response @error {
|
|
479
|
+
respond * 503 {
|
|
480
|
+
body "Service Unavailable"
|
|
481
|
+
close
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
`;
|
|
488
|
+
await this.writeCaddyfile();
|
|
489
|
+
}
|
|
490
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
491
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
492
|
+
if (!this.locked) {
|
|
493
|
+
if (await tryPort(443))
|
|
494
|
+
await kill(443);
|
|
495
|
+
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
496
|
+
await kill(80);
|
|
497
|
+
}
|
|
431
498
|
return new Promise((resolve, reject) => {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
consola.error(e);
|
|
478
|
-
consola.fail("restore host failed\n");
|
|
479
|
-
} finally {
|
|
480
|
-
this.stoped = true;
|
|
481
|
-
import_node_process4.default.nextTick(() => {
|
|
482
|
-
originalExit(code);
|
|
483
|
-
});
|
|
484
|
-
}
|
|
499
|
+
var _a, _b;
|
|
500
|
+
const setupCleanup = () => {
|
|
501
|
+
import_node_process4.default.on("SIGINT", async () => {
|
|
502
|
+
if (this.stoped)
|
|
503
|
+
return;
|
|
504
|
+
import_node_process4.default.stdin.resume();
|
|
505
|
+
try {
|
|
506
|
+
await this.baseCleanup(restore);
|
|
507
|
+
} finally {
|
|
508
|
+
this.stoped = true;
|
|
509
|
+
import_node_process4.default.nextTick(() => {
|
|
510
|
+
import_node_process4.default.exit();
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
515
|
+
import_node_process4.default.exit = async (code) => {
|
|
516
|
+
const port = Number(source.split(":")[1]);
|
|
517
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
518
|
+
await kill(port);
|
|
519
|
+
const pwd = import_node_process4.default.cwd();
|
|
520
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
521
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
522
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
523
|
+
});
|
|
524
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
525
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
526
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
527
|
+
});
|
|
528
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
529
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
530
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
531
|
+
});
|
|
532
|
+
if (this.stoped)
|
|
533
|
+
return originalExit(code);
|
|
534
|
+
import_node_process4.default.stdin.resume();
|
|
535
|
+
try {
|
|
536
|
+
await this.baseCleanup();
|
|
537
|
+
} finally {
|
|
538
|
+
this.stoped = true;
|
|
539
|
+
import_node_process4.default.nextTick(() => {
|
|
540
|
+
originalExit(code);
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
};
|
|
485
544
|
};
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
545
|
+
if (!this.locked) {
|
|
546
|
+
this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
|
|
547
|
+
lockfile.lockSync(caddyLockFilePath);
|
|
548
|
+
this._caddyChild.on("error", (err) => {
|
|
549
|
+
return reject(err);
|
|
550
|
+
});
|
|
551
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", async (data) => {
|
|
552
|
+
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
553
|
+
for (const line of lines) {
|
|
554
|
+
showCaddyLog && line && console.info(line);
|
|
555
|
+
if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
|
|
556
|
+
if (line.includes("parsing caddyfile tokens")) {
|
|
557
|
+
consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
|
|
558
|
+
|
|
559
|
+
${line}
|
|
560
|
+
`);
|
|
561
|
+
await this.baseCleanup();
|
|
562
|
+
import_node_process4.default.exit();
|
|
563
|
+
} else {
|
|
564
|
+
consola.error(`${line}
|
|
565
|
+
`);
|
|
566
|
+
return reject(line);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (line.includes("config file changed"))
|
|
570
|
+
consola.success("Detect added a new reverse proxy config, restarted.\n");
|
|
571
|
+
if (line.includes("caddy proxying") || line.includes("serving initial"))
|
|
572
|
+
return resolve();
|
|
493
573
|
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
574
|
+
});
|
|
575
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
576
|
+
consola.info(_data.toString());
|
|
577
|
+
resolve();
|
|
578
|
+
});
|
|
579
|
+
setupCleanup();
|
|
580
|
+
} else {
|
|
581
|
+
consola.info("Caddy is running in another process.");
|
|
582
|
+
setupCleanup();
|
|
583
|
+
return resolve();
|
|
584
|
+
}
|
|
500
585
|
});
|
|
501
586
|
}
|
|
587
|
+
async baseCleanup(restore = true) {
|
|
588
|
+
var _a;
|
|
589
|
+
try {
|
|
590
|
+
if (restore && this._source && this._target) {
|
|
591
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
592
|
+
consola.success("Restore host success.\n");
|
|
593
|
+
else
|
|
594
|
+
consola.fail("Restore host failed.\n");
|
|
595
|
+
}
|
|
596
|
+
} catch (e) {
|
|
597
|
+
consola.error(e);
|
|
598
|
+
consola.fail("Restore host failed.\n");
|
|
599
|
+
}
|
|
600
|
+
if (!this.locked && !this.stoped) {
|
|
601
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
602
|
+
try {
|
|
603
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
604
|
+
});
|
|
605
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
606
|
+
});
|
|
607
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
608
|
+
});
|
|
609
|
+
} catch (e) {
|
|
610
|
+
consola.error(e);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
502
614
|
};
|
|
503
615
|
|
|
504
616
|
// src/index.ts
|
|
@@ -510,9 +622,10 @@ var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
|
510
622
|
if (caddy)
|
|
511
623
|
return;
|
|
512
624
|
caddy = new CaddyInstant();
|
|
513
|
-
caddy.run(source, target,
|
|
514
|
-
base
|
|
515
|
-
|
|
625
|
+
caddy.run(source, target, {
|
|
626
|
+
base,
|
|
627
|
+
...options
|
|
628
|
+
}).then(() => {
|
|
516
629
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
517
630
|
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
518
631
|
}).catch((e) => {
|
|
@@ -530,16 +643,16 @@ var unpluginFactory = (options) => ({
|
|
|
530
643
|
var _a;
|
|
531
644
|
if (config.command !== "serve")
|
|
532
645
|
return;
|
|
533
|
-
if (!isAdmin()) {
|
|
534
|
-
consola.warn("please run as administrator");
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
646
|
const {
|
|
538
647
|
enable = true,
|
|
539
648
|
target = ""
|
|
540
649
|
} = options;
|
|
541
650
|
if (!enable)
|
|
542
651
|
return;
|
|
652
|
+
if (!isAdmin()) {
|
|
653
|
+
consola.warn("please run as administrator");
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
543
656
|
if (!target) {
|
|
544
657
|
consola.fail("please provide target");
|
|
545
658
|
return;
|
|
@@ -559,24 +672,27 @@ var unpluginFactory = (options) => ({
|
|
|
559
672
|
var _a, _b;
|
|
560
673
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
561
674
|
return;
|
|
562
|
-
if (!isAdmin()) {
|
|
563
|
-
consola.warn("please run as administrator");
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
675
|
const {
|
|
567
676
|
enable = true,
|
|
568
677
|
target = ""
|
|
569
678
|
} = options;
|
|
570
679
|
if (!enable)
|
|
571
680
|
return;
|
|
681
|
+
if (!isAdmin()) {
|
|
682
|
+
consola.warn("please run as administrator");
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
572
685
|
if (!target) {
|
|
573
686
|
consola.fail("please provide target");
|
|
574
687
|
return;
|
|
575
688
|
}
|
|
576
|
-
const devServer =
|
|
689
|
+
const devServer = {
|
|
577
690
|
host: "localhost",
|
|
578
|
-
port: 8080
|
|
579
|
-
|
|
691
|
+
port: 8080,
|
|
692
|
+
...compiler.options.devServer,
|
|
693
|
+
// @ts-expect-error vuecli
|
|
694
|
+
...(_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer
|
|
695
|
+
};
|
|
580
696
|
const source = `${devServer.host}:${devServer.port}`;
|
|
581
697
|
if (caddy)
|
|
582
698
|
return;
|
|
@@ -591,7 +707,9 @@ var unpluginFactory = (options) => ({
|
|
|
591
707
|
options.https = false;
|
|
592
708
|
}
|
|
593
709
|
caddy = new CaddyInstant();
|
|
594
|
-
caddy.run(source, target,
|
|
710
|
+
caddy.run(source, target, {
|
|
711
|
+
...options
|
|
712
|
+
}).then(() => {
|
|
595
713
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
596
714
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
597
715
|
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
@@ -604,31 +722,35 @@ var unpluginFactory = (options) => ({
|
|
|
604
722
|
var _a, _b, _c;
|
|
605
723
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
606
724
|
return;
|
|
607
|
-
if (!isAdmin()) {
|
|
608
|
-
consola.warn("please run as administrator");
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
725
|
const {
|
|
612
726
|
enable = true,
|
|
613
727
|
target = ""
|
|
614
728
|
} = options;
|
|
615
729
|
if (!enable)
|
|
616
730
|
return;
|
|
731
|
+
if (!isAdmin()) {
|
|
732
|
+
consola.warn("please run as administrator");
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
617
735
|
if (!target) {
|
|
618
736
|
consola.fail("please provide target");
|
|
619
737
|
return;
|
|
620
738
|
}
|
|
621
|
-
const devServer =
|
|
739
|
+
const devServer = {
|
|
622
740
|
host: "localhost",
|
|
623
|
-
port: 8080
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
741
|
+
port: 8080,
|
|
742
|
+
...compiler.options.devServer,
|
|
743
|
+
...(_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
744
|
+
cwd
|
|
745
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server
|
|
746
|
+
};
|
|
627
747
|
const source = `${devServer.host}:${devServer.port}`;
|
|
628
748
|
if (caddy)
|
|
629
749
|
return;
|
|
630
750
|
caddy = new CaddyInstant();
|
|
631
|
-
caddy.run(source, target,
|
|
751
|
+
caddy.run(source, target, {
|
|
752
|
+
...options
|
|
753
|
+
}).then(() => {
|
|
632
754
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
633
755
|
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
634
756
|
}).catch((e) => {
|
|
@@ -644,4 +766,4 @@ var src_default = unplugin;
|
|
|
644
766
|
unpluginFactory,
|
|
645
767
|
vitePrintUrls
|
|
646
768
|
});
|
|
647
|
-
exports.default = module.exports;
|
|
769
|
+
module.exports = module.exports;exports.default = module.exports;
|
package/dist/index.js
CHANGED