unplugin-https-reverse-proxy 1.0.0-beta.16 → 1.0.0-beta.18
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-QMYDD3HL.js → chunk-ZDL3GBDQ.js} +66 -47
- package/dist/esbuild.cjs +68 -49
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +68 -49
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +68 -49
- package/dist/nuxt.js +1 -1
- package/dist/rollup.cjs +68 -49
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +68 -49
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +68 -49
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +68 -49
- package/dist/webpack.js +1 -1
- package/package.json +5 -4
- package/scripts/postinstall.cjs +7 -12
- package/src/caddy/index.ts +46 -40
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
package/dist/vite.cjs
CHANGED
|
@@ -83,24 +83,21 @@ function isAdmin() {
|
|
|
83
83
|
var import_node_os2 = require("os");
|
|
84
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
85
85
|
var import_node_fs2 = require("fs");
|
|
86
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
87
|
var import_promises2 = require("fs/promises");
|
|
88
88
|
var import_got_cjs = require("got-cjs");
|
|
89
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
90
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
91
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
92
91
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
93
92
|
|
|
94
93
|
// src/host/index.ts
|
|
95
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
96
95
|
var import_node_child_process2 = require("child_process");
|
|
97
96
|
var import_node_fs = require("fs");
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
103
|
-
});
|
|
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);
|
|
104
101
|
function getPathOfSystemHostsPath() {
|
|
105
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
106
103
|
}
|
|
@@ -121,20 +118,18 @@ async function syncHost() {
|
|
|
121
118
|
async function addHost(ip, host) {
|
|
122
119
|
if (import_node_process2.default.platform !== "win32")
|
|
123
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
126
123
|
if (ip === "localhost")
|
|
127
|
-
|
|
128
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
129
125
|
return await syncHost();
|
|
130
126
|
}
|
|
131
127
|
async function removeHost(ip, host) {
|
|
132
128
|
if (import_node_process2.default.platform !== "win32")
|
|
133
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
134
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
135
131
|
if (ip === "localhost")
|
|
136
|
-
|
|
137
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
138
133
|
return await syncHost();
|
|
139
134
|
}
|
|
140
135
|
|
|
@@ -268,6 +263,7 @@ var supportList = [
|
|
|
268
263
|
|
|
269
264
|
// src/caddy/utils.ts
|
|
270
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
271
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
272
268
|
var spinner;
|
|
273
269
|
function tryPort(port) {
|
|
@@ -288,6 +284,18 @@ function tryPort(port) {
|
|
|
288
284
|
}
|
|
289
285
|
});
|
|
290
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
|
+
}
|
|
291
299
|
function getNumber(number) {
|
|
292
300
|
if (number <= 0)
|
|
293
301
|
return "0%";
|
|
@@ -371,7 +379,7 @@ function testCaddy() {
|
|
|
371
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
372
380
|
return resolve(false);
|
|
373
381
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
374
|
-
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]);
|
|
375
383
|
child.on("close", () => {
|
|
376
384
|
return resolve(false);
|
|
377
385
|
});
|
|
@@ -440,6 +448,8 @@ var CaddyInstant = class {
|
|
|
440
448
|
showCaddyLog = false,
|
|
441
449
|
https = false
|
|
442
450
|
} = options || {};
|
|
451
|
+
this._source = source;
|
|
452
|
+
this._target = target;
|
|
443
453
|
if (!this.inited)
|
|
444
454
|
await this.init();
|
|
445
455
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
@@ -460,24 +470,19 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
460
470
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
461
471
|
if (!this.locked) {
|
|
462
472
|
if (await tryPort(443))
|
|
463
|
-
await (
|
|
473
|
+
await kill(443);
|
|
464
474
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
465
|
-
await (
|
|
475
|
+
await kill(80);
|
|
466
476
|
}
|
|
467
477
|
return new Promise((resolve, reject) => {
|
|
478
|
+
var _a, _b;
|
|
468
479
|
const setupCleanup = () => {
|
|
469
480
|
import_node_process4.default.on("SIGINT", async () => {
|
|
470
|
-
if (
|
|
481
|
+
if (this.stoped)
|
|
471
482
|
return;
|
|
472
|
-
|
|
483
|
+
import_node_process4.default.stdin.resume();
|
|
473
484
|
try {
|
|
474
|
-
|
|
475
|
-
consola.success("Restore host success.\n");
|
|
476
|
-
else
|
|
477
|
-
consola.fail("Restore host failed.\n");
|
|
478
|
-
} catch (e) {
|
|
479
|
-
consola.error(e);
|
|
480
|
-
consola.fail("Restore host failed.\n");
|
|
485
|
+
await this.baseCleanup(restore);
|
|
481
486
|
} finally {
|
|
482
487
|
this.stoped = true;
|
|
483
488
|
import_node_process4.default.nextTick(() => {
|
|
@@ -489,28 +494,25 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
489
494
|
import_node_process4.default.exit = async (code) => {
|
|
490
495
|
const port = Number(source.split(":")[1]);
|
|
491
496
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
492
|
-
await (
|
|
497
|
+
await kill(port);
|
|
493
498
|
const pwd = import_node_process4.default.cwd();
|
|
494
499
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
495
500
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
496
|
-
chmodRecursive(viteCacheDir, 511)
|
|
501
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
502
|
+
});
|
|
497
503
|
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
498
504
|
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
499
|
-
await chmodRecursive(nuxtCacheDir, 511)
|
|
505
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
506
|
+
});
|
|
500
507
|
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
501
508
|
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
502
|
-
chmodRecursive(webpackCacheDir, 511)
|
|
503
|
-
|
|
509
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
510
|
+
});
|
|
511
|
+
if (this.stoped)
|
|
504
512
|
return originalExit(code);
|
|
505
|
-
|
|
513
|
+
import_node_process4.default.stdin.resume();
|
|
506
514
|
try {
|
|
507
|
-
|
|
508
|
-
consola.success("Restore host success.\n");
|
|
509
|
-
else
|
|
510
|
-
consola.fail("Restore host failed.\n");
|
|
511
|
-
} catch (e) {
|
|
512
|
-
consola.error(e);
|
|
513
|
-
consola.fail("Restore host failed.\n");
|
|
515
|
+
await this.baseCleanup();
|
|
514
516
|
} finally {
|
|
515
517
|
this.stoped = true;
|
|
516
518
|
import_node_process4.default.nextTick(() => {
|
|
@@ -520,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
520
522
|
};
|
|
521
523
|
};
|
|
522
524
|
if (!this.locked) {
|
|
523
|
-
|
|
525
|
+
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"]);
|
|
524
526
|
lockfile.lockSync(caddyLockFilePath);
|
|
525
|
-
|
|
527
|
+
this._caddyChild.on("error", (err) => {
|
|
526
528
|
return reject(err);
|
|
527
529
|
});
|
|
528
|
-
|
|
530
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
529
531
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
530
532
|
for (const line of lines) {
|
|
531
533
|
showCaddyLog && line && console.info(line);
|
|
@@ -540,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
540
542
|
return resolve();
|
|
541
543
|
}
|
|
542
544
|
});
|
|
543
|
-
|
|
545
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
544
546
|
consola.info(_data.toString());
|
|
545
547
|
resolve();
|
|
546
548
|
});
|
|
@@ -552,13 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
552
554
|
}
|
|
553
555
|
});
|
|
554
556
|
}
|
|
555
|
-
async baseCleanup() {
|
|
556
|
-
|
|
557
|
+
async baseCleanup(restore = true) {
|
|
558
|
+
var _a;
|
|
559
|
+
try {
|
|
560
|
+
if (restore && this._source && this._target) {
|
|
561
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
562
|
+
consola.success("Restore host success.\n");
|
|
563
|
+
else
|
|
564
|
+
consola.fail("Restore host failed.\n");
|
|
565
|
+
}
|
|
566
|
+
} catch (e) {
|
|
567
|
+
consola.error(e);
|
|
568
|
+
consola.fail("Restore host failed.\n");
|
|
569
|
+
}
|
|
570
|
+
if (!this.locked && !this.stoped) {
|
|
571
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
557
572
|
try {
|
|
558
|
-
await lockfile.unlock(caddyLockFilePath)
|
|
559
|
-
|
|
560
|
-
await (0, import_promises2.unlink)(
|
|
573
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
574
|
+
});
|
|
575
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
576
|
+
});
|
|
577
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
578
|
+
});
|
|
561
579
|
} catch (e) {
|
|
580
|
+
consola.error(e);
|
|
562
581
|
}
|
|
563
582
|
}
|
|
564
583
|
}
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -83,24 +83,21 @@ function isAdmin() {
|
|
|
83
83
|
var import_node_os2 = require("os");
|
|
84
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
85
85
|
var import_node_fs2 = require("fs");
|
|
86
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
87
|
var import_promises2 = require("fs/promises");
|
|
88
88
|
var import_got_cjs = require("got-cjs");
|
|
89
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
90
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
91
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
92
91
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
93
92
|
|
|
94
93
|
// src/host/index.ts
|
|
95
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
96
95
|
var import_node_child_process2 = require("child_process");
|
|
97
96
|
var import_node_fs = require("fs");
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
var
|
|
101
|
-
|
|
102
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
103
|
-
});
|
|
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);
|
|
104
101
|
function getPathOfSystemHostsPath() {
|
|
105
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
106
103
|
}
|
|
@@ -121,20 +118,18 @@ async function syncHost() {
|
|
|
121
118
|
async function addHost(ip, host) {
|
|
122
119
|
if (import_node_process2.default.platform !== "win32")
|
|
123
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
126
123
|
if (ip === "localhost")
|
|
127
|
-
|
|
128
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
129
125
|
return await syncHost();
|
|
130
126
|
}
|
|
131
127
|
async function removeHost(ip, host) {
|
|
132
128
|
if (import_node_process2.default.platform !== "win32")
|
|
133
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
134
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
135
131
|
if (ip === "localhost")
|
|
136
|
-
|
|
137
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
138
133
|
return await syncHost();
|
|
139
134
|
}
|
|
140
135
|
|
|
@@ -268,6 +263,7 @@ var supportList = [
|
|
|
268
263
|
|
|
269
264
|
// src/caddy/utils.ts
|
|
270
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
271
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
272
268
|
var spinner;
|
|
273
269
|
function tryPort(port) {
|
|
@@ -288,6 +284,18 @@ function tryPort(port) {
|
|
|
288
284
|
}
|
|
289
285
|
});
|
|
290
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
|
+
}
|
|
291
299
|
function getNumber(number) {
|
|
292
300
|
if (number <= 0)
|
|
293
301
|
return "0%";
|
|
@@ -371,7 +379,7 @@ function testCaddy() {
|
|
|
371
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
372
380
|
return resolve(false);
|
|
373
381
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
374
|
-
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]);
|
|
375
383
|
child.on("close", () => {
|
|
376
384
|
return resolve(false);
|
|
377
385
|
});
|
|
@@ -440,6 +448,8 @@ var CaddyInstant = class {
|
|
|
440
448
|
showCaddyLog = false,
|
|
441
449
|
https = false
|
|
442
450
|
} = options || {};
|
|
451
|
+
this._source = source;
|
|
452
|
+
this._target = target;
|
|
443
453
|
if (!this.inited)
|
|
444
454
|
await this.init();
|
|
445
455
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
@@ -460,24 +470,19 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
460
470
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
461
471
|
if (!this.locked) {
|
|
462
472
|
if (await tryPort(443))
|
|
463
|
-
await (
|
|
473
|
+
await kill(443);
|
|
464
474
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
465
|
-
await (
|
|
475
|
+
await kill(80);
|
|
466
476
|
}
|
|
467
477
|
return new Promise((resolve, reject) => {
|
|
478
|
+
var _a, _b;
|
|
468
479
|
const setupCleanup = () => {
|
|
469
480
|
import_node_process4.default.on("SIGINT", async () => {
|
|
470
|
-
if (
|
|
481
|
+
if (this.stoped)
|
|
471
482
|
return;
|
|
472
|
-
|
|
483
|
+
import_node_process4.default.stdin.resume();
|
|
473
484
|
try {
|
|
474
|
-
|
|
475
|
-
consola.success("Restore host success.\n");
|
|
476
|
-
else
|
|
477
|
-
consola.fail("Restore host failed.\n");
|
|
478
|
-
} catch (e) {
|
|
479
|
-
consola.error(e);
|
|
480
|
-
consola.fail("Restore host failed.\n");
|
|
485
|
+
await this.baseCleanup(restore);
|
|
481
486
|
} finally {
|
|
482
487
|
this.stoped = true;
|
|
483
488
|
import_node_process4.default.nextTick(() => {
|
|
@@ -489,28 +494,25 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
489
494
|
import_node_process4.default.exit = async (code) => {
|
|
490
495
|
const port = Number(source.split(":")[1]);
|
|
491
496
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
492
|
-
await (
|
|
497
|
+
await kill(port);
|
|
493
498
|
const pwd = import_node_process4.default.cwd();
|
|
494
499
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
495
500
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
496
|
-
chmodRecursive(viteCacheDir, 511)
|
|
501
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
502
|
+
});
|
|
497
503
|
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
498
504
|
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
499
|
-
await chmodRecursive(nuxtCacheDir, 511)
|
|
505
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
506
|
+
});
|
|
500
507
|
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
501
508
|
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
502
|
-
chmodRecursive(webpackCacheDir, 511)
|
|
503
|
-
|
|
509
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
510
|
+
});
|
|
511
|
+
if (this.stoped)
|
|
504
512
|
return originalExit(code);
|
|
505
|
-
|
|
513
|
+
import_node_process4.default.stdin.resume();
|
|
506
514
|
try {
|
|
507
|
-
|
|
508
|
-
consola.success("Restore host success.\n");
|
|
509
|
-
else
|
|
510
|
-
consola.fail("Restore host failed.\n");
|
|
511
|
-
} catch (e) {
|
|
512
|
-
consola.error(e);
|
|
513
|
-
consola.fail("Restore host failed.\n");
|
|
515
|
+
await this.baseCleanup();
|
|
514
516
|
} finally {
|
|
515
517
|
this.stoped = true;
|
|
516
518
|
import_node_process4.default.nextTick(() => {
|
|
@@ -520,12 +522,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
520
522
|
};
|
|
521
523
|
};
|
|
522
524
|
if (!this.locked) {
|
|
523
|
-
|
|
525
|
+
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"]);
|
|
524
526
|
lockfile.lockSync(caddyLockFilePath);
|
|
525
|
-
|
|
527
|
+
this._caddyChild.on("error", (err) => {
|
|
526
528
|
return reject(err);
|
|
527
529
|
});
|
|
528
|
-
|
|
530
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
529
531
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
530
532
|
for (const line of lines) {
|
|
531
533
|
showCaddyLog && line && console.info(line);
|
|
@@ -540,7 +542,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
540
542
|
return resolve();
|
|
541
543
|
}
|
|
542
544
|
});
|
|
543
|
-
|
|
545
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
544
546
|
consola.info(_data.toString());
|
|
545
547
|
resolve();
|
|
546
548
|
});
|
|
@@ -552,13 +554,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
552
554
|
}
|
|
553
555
|
});
|
|
554
556
|
}
|
|
555
|
-
async baseCleanup() {
|
|
556
|
-
|
|
557
|
+
async baseCleanup(restore = true) {
|
|
558
|
+
var _a;
|
|
559
|
+
try {
|
|
560
|
+
if (restore && this._source && this._target) {
|
|
561
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
562
|
+
consola.success("Restore host success.\n");
|
|
563
|
+
else
|
|
564
|
+
consola.fail("Restore host failed.\n");
|
|
565
|
+
}
|
|
566
|
+
} catch (e) {
|
|
567
|
+
consola.error(e);
|
|
568
|
+
consola.fail("Restore host failed.\n");
|
|
569
|
+
}
|
|
570
|
+
if (!this.locked && !this.stoped) {
|
|
571
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
557
572
|
try {
|
|
558
|
-
await lockfile.unlock(caddyLockFilePath)
|
|
559
|
-
|
|
560
|
-
await (0, import_promises2.unlink)(
|
|
573
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
574
|
+
});
|
|
575
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
576
|
+
});
|
|
577
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
578
|
+
});
|
|
561
579
|
} catch (e) {
|
|
580
|
+
consola.error(e);
|
|
562
581
|
}
|
|
563
582
|
}
|
|
564
583
|
}
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-https-reverse-proxy",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.18",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/zcf0508/unplugin-https-reverse-proxy#readme",
|
|
@@ -119,10 +119,9 @@
|
|
|
119
119
|
"consola": "^3.2.3",
|
|
120
120
|
"dotenv-flow": "^4.1.0",
|
|
121
121
|
"got-cjs": "^12.5.4",
|
|
122
|
-
"
|
|
122
|
+
"hostile": "^1.4.0",
|
|
123
123
|
"http-proxy-agent": "^7.0.2",
|
|
124
124
|
"https-proxy-agent": "^7.0.4",
|
|
125
|
-
"kill-port": "^2.0.1",
|
|
126
125
|
"ora": "5",
|
|
127
126
|
"picocolors": "^1.0.0",
|
|
128
127
|
"tsx": "^4.7.1",
|
|
@@ -134,12 +133,14 @@
|
|
|
134
133
|
"@nuxt/schema": "^3.10.2",
|
|
135
134
|
"@rsbuild/core": "^0.4.3",
|
|
136
135
|
"@rspack/core": "^0.5.4",
|
|
136
|
+
"@types/hostile": "^1.3.5",
|
|
137
137
|
"@types/kill-port": "^2.0.3",
|
|
138
138
|
"@types/node": "^20.11.19",
|
|
139
139
|
"@types/proper-lockfile": "^4.1.4",
|
|
140
140
|
"@vue/cli": "^5.0.8",
|
|
141
141
|
"bumpp": "^9.3.0",
|
|
142
142
|
"chalk": "^5.3.0",
|
|
143
|
+
"cross-env": "^7.0.3",
|
|
143
144
|
"eslint": "^8.56.0",
|
|
144
145
|
"fast-glob": "^3.3.2",
|
|
145
146
|
"nodemon": "^3.0.3",
|
|
@@ -165,6 +166,6 @@
|
|
|
165
166
|
"play:vuecli4": "npm -C examples/vuecli4 run serve",
|
|
166
167
|
"release": "bumpp",
|
|
167
168
|
"start": "tsx src/index.ts",
|
|
168
|
-
"test": "UHRP_CADDY_PATH='./test/.uhrp' vitest"
|
|
169
|
+
"test": "cross-env UHRP_CADDY_PATH='./test/.uhrp' vitest"
|
|
169
170
|
}
|
|
170
171
|
}
|
package/scripts/postinstall.cjs
CHANGED
|
@@ -49,27 +49,21 @@ function once(fn) {
|
|
|
49
49
|
var import_node_os2 = require("os");
|
|
50
50
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
51
51
|
var import_node_fs2 = require("fs");
|
|
52
|
-
var
|
|
52
|
+
var import_node_child_process4 = require("child_process");
|
|
53
53
|
var import_promises2 = require("fs/promises");
|
|
54
54
|
var import_got_cjs = require("got-cjs");
|
|
55
55
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
56
56
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
57
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
58
57
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
59
58
|
|
|
60
59
|
// src/host/index.ts
|
|
61
60
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
62
61
|
var import_node_child_process2 = require("child_process");
|
|
63
62
|
var import_node_fs = require("fs");
|
|
64
|
-
var
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
69
|
-
});
|
|
70
|
-
function getPathOfSystemHostsPath() {
|
|
71
|
-
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
72
|
-
}
|
|
63
|
+
var import_node_util = require("util");
|
|
64
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
65
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
66
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
73
67
|
|
|
74
68
|
// src/caddy/constants.ts
|
|
75
69
|
var import_node_path2 = require("path");
|
|
@@ -201,6 +195,7 @@ var supportList = [
|
|
|
201
195
|
|
|
202
196
|
// src/caddy/utils.ts
|
|
203
197
|
var import_node_net = require("net");
|
|
198
|
+
var import_node_child_process3 = require("child_process");
|
|
204
199
|
var import_ora = __toESM(require("ora"), 1);
|
|
205
200
|
var spinner;
|
|
206
201
|
function getNumber(number) {
|
|
@@ -286,7 +281,7 @@ function testCaddy() {
|
|
|
286
281
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
287
282
|
return resolve(false);
|
|
288
283
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
289
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
284
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
290
285
|
child.on("close", () => {
|
|
291
286
|
return resolve(false);
|
|
292
287
|
});
|