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/rollup.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/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -82,24 +82,21 @@ function isAdmin() {
|
|
|
82
82
|
var import_node_os2 = require("os");
|
|
83
83
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
84
84
|
var import_node_fs2 = require("fs");
|
|
85
|
-
var
|
|
85
|
+
var import_node_child_process4 = require("child_process");
|
|
86
86
|
var import_promises2 = require("fs/promises");
|
|
87
87
|
var import_got_cjs = require("got-cjs");
|
|
88
88
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
89
89
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
90
|
-
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
91
90
|
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
92
91
|
|
|
93
92
|
// src/host/index.ts
|
|
94
93
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
95
94
|
var import_node_child_process2 = require("child_process");
|
|
96
95
|
var import_node_fs = require("fs");
|
|
97
|
-
var
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
102
|
-
});
|
|
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);
|
|
103
100
|
function getPathOfSystemHostsPath() {
|
|
104
101
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
105
102
|
}
|
|
@@ -120,20 +117,18 @@ async function syncHost() {
|
|
|
120
117
|
async function addHost(ip, host) {
|
|
121
118
|
if (import_node_process2.default.platform !== "win32")
|
|
122
119
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
await _setHost("127.0.0.1", "localhost");
|
|
121
|
+
await _setHost(ip, host);
|
|
125
122
|
if (ip === "localhost")
|
|
126
|
-
|
|
127
|
-
await hostInstance.updateFinish();
|
|
123
|
+
await _setHost("127.0.0.1", host);
|
|
128
124
|
return await syncHost();
|
|
129
125
|
}
|
|
130
126
|
async function removeHost(ip, host) {
|
|
131
127
|
if (import_node_process2.default.platform !== "win32")
|
|
132
128
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
133
|
-
|
|
129
|
+
await _removeHost(ip, host);
|
|
134
130
|
if (ip === "localhost")
|
|
135
|
-
|
|
136
|
-
await hostInstance.updateFinish();
|
|
131
|
+
await _removeHost("127.0.0.1", host);
|
|
137
132
|
return await syncHost();
|
|
138
133
|
}
|
|
139
134
|
|
|
@@ -267,6 +262,7 @@ var supportList = [
|
|
|
267
262
|
|
|
268
263
|
// src/caddy/utils.ts
|
|
269
264
|
var import_node_net = require("net");
|
|
265
|
+
var import_node_child_process3 = require("child_process");
|
|
270
266
|
var import_ora = __toESM(require("ora"), 1);
|
|
271
267
|
var spinner;
|
|
272
268
|
function tryPort(port) {
|
|
@@ -287,6 +283,18 @@ function tryPort(port) {
|
|
|
287
283
|
}
|
|
288
284
|
});
|
|
289
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
|
+
}
|
|
290
298
|
function getNumber(number) {
|
|
291
299
|
if (number <= 0)
|
|
292
300
|
return "0%";
|
|
@@ -370,7 +378,7 @@ function testCaddy() {
|
|
|
370
378
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
371
379
|
return resolve(false);
|
|
372
380
|
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
373
|
-
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]);
|
|
374
382
|
child.on("close", () => {
|
|
375
383
|
return resolve(false);
|
|
376
384
|
});
|
|
@@ -439,6 +447,8 @@ var CaddyInstant = class {
|
|
|
439
447
|
showCaddyLog = false,
|
|
440
448
|
https = false
|
|
441
449
|
} = options || {};
|
|
450
|
+
this._source = source;
|
|
451
|
+
this._target = target;
|
|
442
452
|
if (!this.inited)
|
|
443
453
|
await this.init();
|
|
444
454
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
@@ -459,24 +469,19 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
459
469
|
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
460
470
|
if (!this.locked) {
|
|
461
471
|
if (await tryPort(443))
|
|
462
|
-
await (
|
|
472
|
+
await kill(443);
|
|
463
473
|
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
464
|
-
await (
|
|
474
|
+
await kill(80);
|
|
465
475
|
}
|
|
466
476
|
return new Promise((resolve, reject) => {
|
|
477
|
+
var _a, _b;
|
|
467
478
|
const setupCleanup = () => {
|
|
468
479
|
import_node_process4.default.on("SIGINT", async () => {
|
|
469
|
-
if (
|
|
480
|
+
if (this.stoped)
|
|
470
481
|
return;
|
|
471
|
-
|
|
482
|
+
import_node_process4.default.stdin.resume();
|
|
472
483
|
try {
|
|
473
|
-
|
|
474
|
-
consola.success("Restore host success.\n");
|
|
475
|
-
else
|
|
476
|
-
consola.fail("Restore host failed.\n");
|
|
477
|
-
} catch (e) {
|
|
478
|
-
consola.error(e);
|
|
479
|
-
consola.fail("Restore host failed.\n");
|
|
484
|
+
await this.baseCleanup(restore);
|
|
480
485
|
} finally {
|
|
481
486
|
this.stoped = true;
|
|
482
487
|
import_node_process4.default.nextTick(() => {
|
|
@@ -488,28 +493,25 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
488
493
|
import_node_process4.default.exit = async (code) => {
|
|
489
494
|
const port = Number(source.split(":")[1]);
|
|
490
495
|
if (!Number.isNaN(port) && await tryPort(port))
|
|
491
|
-
await (
|
|
496
|
+
await kill(port);
|
|
492
497
|
const pwd = import_node_process4.default.cwd();
|
|
493
498
|
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
494
499
|
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
495
|
-
chmodRecursive(viteCacheDir, 511)
|
|
500
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
501
|
+
});
|
|
496
502
|
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
497
503
|
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
498
|
-
await chmodRecursive(nuxtCacheDir, 511)
|
|
504
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
505
|
+
});
|
|
499
506
|
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
500
507
|
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
501
|
-
chmodRecursive(webpackCacheDir, 511)
|
|
502
|
-
|
|
508
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
509
|
+
});
|
|
510
|
+
if (this.stoped)
|
|
503
511
|
return originalExit(code);
|
|
504
|
-
|
|
512
|
+
import_node_process4.default.stdin.resume();
|
|
505
513
|
try {
|
|
506
|
-
|
|
507
|
-
consola.success("Restore host success.\n");
|
|
508
|
-
else
|
|
509
|
-
consola.fail("Restore host failed.\n");
|
|
510
|
-
} catch (e) {
|
|
511
|
-
consola.error(e);
|
|
512
|
-
consola.fail("Restore host failed.\n");
|
|
514
|
+
await this.baseCleanup();
|
|
513
515
|
} finally {
|
|
514
516
|
this.stoped = true;
|
|
515
517
|
import_node_process4.default.nextTick(() => {
|
|
@@ -519,12 +521,12 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
519
521
|
};
|
|
520
522
|
};
|
|
521
523
|
if (!this.locked) {
|
|
522
|
-
|
|
524
|
+
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"]);
|
|
523
525
|
lockfile.lockSync(caddyLockFilePath);
|
|
524
|
-
|
|
526
|
+
this._caddyChild.on("error", (err) => {
|
|
525
527
|
return reject(err);
|
|
526
528
|
});
|
|
527
|
-
|
|
529
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", (data) => {
|
|
528
530
|
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
529
531
|
for (const line of lines) {
|
|
530
532
|
showCaddyLog && line && console.info(line);
|
|
@@ -539,7 +541,7 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
539
541
|
return resolve();
|
|
540
542
|
}
|
|
541
543
|
});
|
|
542
|
-
|
|
544
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
543
545
|
consola.info(_data.toString());
|
|
544
546
|
resolve();
|
|
545
547
|
});
|
|
@@ -551,13 +553,30 @@ ${target.split(":")[0]}${https ? "" : ":80"} {
|
|
|
551
553
|
}
|
|
552
554
|
});
|
|
553
555
|
}
|
|
554
|
-
async baseCleanup() {
|
|
555
|
-
|
|
556
|
+
async baseCleanup(restore = true) {
|
|
557
|
+
var _a;
|
|
558
|
+
try {
|
|
559
|
+
if (restore && this._source && this._target) {
|
|
560
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
561
|
+
consola.success("Restore host success.\n");
|
|
562
|
+
else
|
|
563
|
+
consola.fail("Restore host failed.\n");
|
|
564
|
+
}
|
|
565
|
+
} catch (e) {
|
|
566
|
+
consola.error(e);
|
|
567
|
+
consola.fail("Restore host failed.\n");
|
|
568
|
+
}
|
|
569
|
+
if (!this.locked && !this.stoped) {
|
|
570
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
556
571
|
try {
|
|
557
|
-
await lockfile.unlock(caddyLockFilePath)
|
|
558
|
-
|
|
559
|
-
await (0, import_promises2.unlink)(
|
|
572
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
573
|
+
});
|
|
574
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
575
|
+
});
|
|
576
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
577
|
+
});
|
|
560
578
|
} catch (e) {
|
|
579
|
+
consola.error(e);
|
|
561
580
|
}
|
|
562
581
|
}
|
|
563
582
|
}
|