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