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