unplugin-https-reverse-proxy 0.0.20 → 0.0.21
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/dist/{chunk-CVO5VP4I.js → chunk-3M3YENXO.js} +1 -1
- package/dist/{chunk-VXVYW4ZE.js → chunk-CT3M7EPZ.js} +1 -1
- package/dist/{chunk-KYPQLMHO.js → chunk-NH3VM3RE.js} +13 -3
- package/dist/{chunk-CQC5SSJR.js → chunk-NNO3ZUSU.js} +16 -1
- package/dist/esbuild.cjs +58 -35
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +58 -35
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +58 -35
- package/dist/nuxt.js +4 -4
- package/dist/rollup.cjs +58 -35
- package/dist/rollup.js +2 -2
- package/dist/utils.cjs +26 -0
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +3 -1
- package/dist/vite.cjs +58 -35
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +58 -35
- package/dist/webpack.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +14 -3
- package/src/utils.ts +17 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
__spreadValues,
|
|
3
3
|
consola,
|
|
4
|
+
isAdmin,
|
|
4
5
|
once
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NNO3ZUSU.js";
|
|
6
7
|
|
|
7
8
|
// src/index.ts
|
|
8
9
|
import process3 from "process";
|
|
9
|
-
import { chmodSync as chmodSync2 } from "fs";
|
|
10
|
+
import { chmodSync as chmodSync2, existsSync as existsSync2 } from "fs";
|
|
10
11
|
import { createUnplugin } from "unplugin";
|
|
11
12
|
import c from "picocolors";
|
|
12
13
|
|
|
@@ -420,6 +421,10 @@ var unpluginFactory = (options) => ({
|
|
|
420
421
|
});
|
|
421
422
|
},
|
|
422
423
|
configureServer(server) {
|
|
424
|
+
if (!isAdmin()) {
|
|
425
|
+
consola.warn("please run as administrator");
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
423
428
|
if (config.command === "build")
|
|
424
429
|
return;
|
|
425
430
|
const {
|
|
@@ -439,7 +444,8 @@ var unpluginFactory = (options) => ({
|
|
|
439
444
|
_printUrls();
|
|
440
445
|
const pwd = process3.cwd();
|
|
441
446
|
const vireCacheDir = `${pwd}/node_modules/.vite`;
|
|
442
|
-
|
|
447
|
+
if (existsSync2(vireCacheDir))
|
|
448
|
+
chmodSync2(vireCacheDir, 511);
|
|
443
449
|
let source = `localhost:${config.server.port}`;
|
|
444
450
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
445
451
|
if (url) {
|
|
@@ -467,6 +473,10 @@ var unpluginFactory = (options) => ({
|
|
|
467
473
|
}
|
|
468
474
|
},
|
|
469
475
|
webpack(compiler) {
|
|
476
|
+
if (!isAdmin()) {
|
|
477
|
+
consola.warn("please run as administrator");
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
470
480
|
if (process3.env.NODE_ENV !== "development")
|
|
471
481
|
return;
|
|
472
482
|
const {
|
|
@@ -16,6 +16,8 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// src/utils.ts
|
|
19
|
+
import process from "process";
|
|
20
|
+
import { execSync } from "child_process";
|
|
19
21
|
import { createConsola } from "consola";
|
|
20
22
|
var consola = createConsola({
|
|
21
23
|
level: 3
|
|
@@ -29,9 +31,22 @@ function once(fn) {
|
|
|
29
31
|
return fn(...args);
|
|
30
32
|
};
|
|
31
33
|
}
|
|
34
|
+
function isAdmin() {
|
|
35
|
+
if (process.platform === "win32") {
|
|
36
|
+
try {
|
|
37
|
+
execSync("net session", { stdio: "ignore" });
|
|
38
|
+
return true;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
return process.getuid && process.getuid() === 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
32
46
|
|
|
33
47
|
export {
|
|
34
48
|
__spreadValues,
|
|
35
49
|
consola,
|
|
36
|
-
once
|
|
50
|
+
once,
|
|
51
|
+
isAdmin
|
|
37
52
|
};
|
package/dist/esbuild.cjs
CHANGED
|
@@ -50,12 +50,14 @@ module.exports = __toCommonJS(esbuild_exports);
|
|
|
50
50
|
var import_unplugin2 = require("unplugin");
|
|
51
51
|
|
|
52
52
|
// src/index.ts
|
|
53
|
-
var
|
|
53
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
54
54
|
var import_node_fs2 = require("fs");
|
|
55
55
|
var import_unplugin = require("unplugin");
|
|
56
56
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
57
|
|
|
58
58
|
// src/utils.ts
|
|
59
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
60
|
+
var import_node_child_process = require("child_process");
|
|
59
61
|
var import_consola = require("consola");
|
|
60
62
|
var consola = (0, import_consola.createConsola)({
|
|
61
63
|
level: 3
|
|
@@ -69,12 +71,24 @@ function once(fn) {
|
|
|
69
71
|
return fn(...args);
|
|
70
72
|
};
|
|
71
73
|
}
|
|
74
|
+
function isAdmin() {
|
|
75
|
+
if (import_node_process.default.platform === "win32") {
|
|
76
|
+
try {
|
|
77
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
78
|
+
return true;
|
|
79
|
+
} catch (e) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
72
86
|
|
|
73
87
|
// src/caddy/index.ts
|
|
74
88
|
var import_node_os = require("os");
|
|
75
|
-
var
|
|
89
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
76
90
|
var import_node_fs = require("fs");
|
|
77
|
-
var
|
|
91
|
+
var import_node_child_process2 = require("child_process");
|
|
78
92
|
var import_got_cjs = require("got-cjs");
|
|
79
93
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
80
94
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
@@ -83,9 +97,9 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
83
97
|
|
|
84
98
|
// src/caddy/constants.ts
|
|
85
99
|
var import_node_path = require("path");
|
|
86
|
-
var
|
|
87
|
-
var TEMP_DIR =
|
|
88
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${
|
|
100
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
101
|
+
var TEMP_DIR = import_node_process2.default.env.TEMP || import_node_process2.default.env.TMPDIR || "/tmp";
|
|
102
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process2.default.platform === "win32" ? ".exe" : ""}`);
|
|
89
103
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
90
104
|
var supportList = [
|
|
91
105
|
{
|
|
@@ -262,15 +276,15 @@ async function download() {
|
|
|
262
276
|
const file = (0, import_node_fs.createWriteStream)(caddyPath);
|
|
263
277
|
let _platform = (0, import_node_os.platform)().toString();
|
|
264
278
|
_platform === "win32" && (_platform = "windows");
|
|
265
|
-
let _arch =
|
|
279
|
+
let _arch = import_node_process3.default.arch.toString();
|
|
266
280
|
_arch === "x64" && (_arch = "amd64");
|
|
267
281
|
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
268
282
|
if (!support)
|
|
269
283
|
return reject(new Error("not support"));
|
|
270
284
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
|
|
271
285
|
(0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
|
|
272
|
-
const httpProxy =
|
|
273
|
-
const httpsProxy =
|
|
286
|
+
const httpProxy = import_node_process3.default.env.HTTP_PROXY || import_node_process3.default.env.http_proxy;
|
|
287
|
+
const httpsProxy = import_node_process3.default.env.HTTPS_PROXY || import_node_process3.default.env.https_proxy;
|
|
274
288
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
275
289
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
276
290
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
@@ -282,7 +296,7 @@ async function download() {
|
|
|
282
296
|
logProgress(progress.percent);
|
|
283
297
|
}).pipe(file).on("finish", () => {
|
|
284
298
|
logProgressOver();
|
|
285
|
-
if (
|
|
299
|
+
if (import_node_process3.default.platform === "win32")
|
|
286
300
|
return resolve(caddyPath);
|
|
287
301
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
288
302
|
resolve(caddyPath);
|
|
@@ -296,7 +310,7 @@ function testCaddy() {
|
|
|
296
310
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
297
311
|
return resolve(false);
|
|
298
312
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
299
|
-
const child =
|
|
313
|
+
const child = import_node_process3.default.platform === "win32" ? (0, import_node_child_process2.spawn)(caddyPath, []) : (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath]);
|
|
300
314
|
child.on("close", () => {
|
|
301
315
|
return resolve(false);
|
|
302
316
|
});
|
|
@@ -327,15 +341,15 @@ var CaddyInstant = class {
|
|
|
327
341
|
this.host.add(ip, host);
|
|
328
342
|
await this.host.updateFinish();
|
|
329
343
|
return new Promise((resolve, reject) => {
|
|
330
|
-
if (
|
|
331
|
-
(0,
|
|
344
|
+
if (import_node_process3.default.platform === "win32") {
|
|
345
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
332
346
|
consola.error(err);
|
|
333
347
|
return resolve(false);
|
|
334
348
|
}).on("close", () => {
|
|
335
349
|
resolve(true);
|
|
336
350
|
});
|
|
337
351
|
} else {
|
|
338
|
-
(0,
|
|
352
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
339
353
|
consola.error(err);
|
|
340
354
|
return resolve(false);
|
|
341
355
|
}).on("close", () => {
|
|
@@ -349,15 +363,15 @@ var CaddyInstant = class {
|
|
|
349
363
|
this.host.remove(ip, host);
|
|
350
364
|
await this.host.updateFinish();
|
|
351
365
|
return new Promise((resolve, reject) => {
|
|
352
|
-
if (
|
|
353
|
-
(0,
|
|
366
|
+
if (import_node_process3.default.platform === "win32") {
|
|
367
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
354
368
|
consola.error(err);
|
|
355
369
|
return resolve(false);
|
|
356
370
|
}).on("close", () => {
|
|
357
371
|
resolve(true);
|
|
358
372
|
});
|
|
359
373
|
} else {
|
|
360
|
-
(0,
|
|
374
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
361
375
|
consola.error(err);
|
|
362
376
|
return resolve(false);
|
|
363
377
|
}).on("close", () => {
|
|
@@ -383,13 +397,13 @@ var CaddyInstant = class {
|
|
|
383
397
|
await this.init();
|
|
384
398
|
if (https && await tryPort(443))
|
|
385
399
|
await (0, import_kill_port.default)(443, "tcp");
|
|
386
|
-
if ((
|
|
400
|
+
if ((import_node_process3.default.platform === "win32" || !https) && await tryPort(80))
|
|
387
401
|
await (0, import_kill_port.default)(80, "tcp");
|
|
388
402
|
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
389
403
|
throw new Error("update host failed");
|
|
390
404
|
consola.success("update host success\n");
|
|
391
405
|
return new Promise((resolve, reject) => {
|
|
392
|
-
const child =
|
|
406
|
+
const child = import_node_process3.default.platform !== "win32" ? (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}${https ? "" : ":80"}`, "--to", `${source}`, "--internal-certs", "--insecure", "--disable-redirects"]) : (0, import_node_child_process2.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
393
407
|
child.on("error", (err) => {
|
|
394
408
|
return reject(err);
|
|
395
409
|
});
|
|
@@ -432,30 +446,30 @@ var caddy;
|
|
|
432
446
|
var _stop;
|
|
433
447
|
var _servce;
|
|
434
448
|
function registerExit(clear) {
|
|
435
|
-
|
|
449
|
+
import_node_process4.default.on("beforeExit", async (_code) => {
|
|
436
450
|
await clear();
|
|
437
451
|
});
|
|
438
|
-
|
|
452
|
+
import_node_process4.default.on("uncaughtException", async (err) => {
|
|
439
453
|
console.error("An uncaught error occurred!", err.stack);
|
|
440
454
|
await clear();
|
|
441
|
-
|
|
442
|
-
|
|
455
|
+
import_node_process4.default.nextTick(() => {
|
|
456
|
+
import_node_process4.default.exit(1);
|
|
443
457
|
});
|
|
444
458
|
});
|
|
445
|
-
|
|
459
|
+
import_node_process4.default.on("unhandledRejection", async (reason, promise) => {
|
|
446
460
|
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
447
461
|
await clear();
|
|
448
|
-
|
|
449
|
-
|
|
462
|
+
import_node_process4.default.nextTick(() => {
|
|
463
|
+
import_node_process4.default.exit(1);
|
|
450
464
|
});
|
|
451
465
|
});
|
|
452
|
-
|
|
466
|
+
import_node_process4.default.once("SIGINT", async () => {
|
|
453
467
|
await clear();
|
|
454
|
-
|
|
468
|
+
import_node_process4.default.exit(0);
|
|
455
469
|
});
|
|
456
|
-
|
|
470
|
+
import_node_process4.default.once("SIGTERM", async () => {
|
|
457
471
|
await clear();
|
|
458
|
-
|
|
472
|
+
import_node_process4.default.exit(0);
|
|
459
473
|
});
|
|
460
474
|
}
|
|
461
475
|
var unpluginFactory = (options) => ({
|
|
@@ -480,6 +494,10 @@ var unpluginFactory = (options) => ({
|
|
|
480
494
|
});
|
|
481
495
|
},
|
|
482
496
|
configureServer(server) {
|
|
497
|
+
if (!isAdmin()) {
|
|
498
|
+
consola.warn("please run as administrator");
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
483
501
|
if (config.command === "build")
|
|
484
502
|
return;
|
|
485
503
|
const {
|
|
@@ -497,9 +515,10 @@ var unpluginFactory = (options) => ({
|
|
|
497
515
|
server.printUrls = () => {
|
|
498
516
|
var _a;
|
|
499
517
|
_printUrls();
|
|
500
|
-
const pwd =
|
|
518
|
+
const pwd = import_node_process4.default.cwd();
|
|
501
519
|
const vireCacheDir = `${pwd}/node_modules/.vite`;
|
|
502
|
-
(0, import_node_fs2.
|
|
520
|
+
if ((0, import_node_fs2.existsSync)(vireCacheDir))
|
|
521
|
+
(0, import_node_fs2.chmodSync)(vireCacheDir, 511);
|
|
503
522
|
let source = `localhost:${config.server.port}`;
|
|
504
523
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
505
524
|
if (url) {
|
|
@@ -527,7 +546,11 @@ var unpluginFactory = (options) => ({
|
|
|
527
546
|
}
|
|
528
547
|
},
|
|
529
548
|
webpack(compiler) {
|
|
530
|
-
if (
|
|
549
|
+
if (!isAdmin()) {
|
|
550
|
+
consola.warn("please run as administrator");
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (import_node_process4.default.env.NODE_ENV !== "development")
|
|
531
554
|
return;
|
|
532
555
|
const {
|
|
533
556
|
enable = true,
|
|
@@ -543,7 +566,7 @@ var unpluginFactory = (options) => ({
|
|
|
543
566
|
const devServer = __spreadValues(__spreadValues({
|
|
544
567
|
host: "localhost",
|
|
545
568
|
port: 8080
|
|
546
|
-
}, compiler.options.devServer),
|
|
569
|
+
}, compiler.options.devServer), import_node_process4.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
547
570
|
const source = `${devServer.host}:${devServer.port}`;
|
|
548
571
|
if (caddy)
|
|
549
572
|
return;
|
|
@@ -555,7 +578,7 @@ var unpluginFactory = (options) => ({
|
|
|
555
578
|
});
|
|
556
579
|
} catch (e) {
|
|
557
580
|
consola.error(e);
|
|
558
|
-
|
|
581
|
+
import_node_process4.default.exit(1);
|
|
559
582
|
}
|
|
560
583
|
};
|
|
561
584
|
caddy = new CaddyInstant();
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -49,12 +49,14 @@ __export(src_exports, {
|
|
|
49
49
|
unpluginFactory: () => unpluginFactory
|
|
50
50
|
});
|
|
51
51
|
module.exports = __toCommonJS(src_exports);
|
|
52
|
-
var
|
|
52
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
53
53
|
var import_node_fs2 = require("fs");
|
|
54
54
|
var import_unplugin = require("unplugin");
|
|
55
55
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
56
56
|
|
|
57
57
|
// src/utils.ts
|
|
58
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
59
|
+
var import_node_child_process = require("child_process");
|
|
58
60
|
var import_consola = require("consola");
|
|
59
61
|
var consola = (0, import_consola.createConsola)({
|
|
60
62
|
level: 3
|
|
@@ -68,12 +70,24 @@ function once(fn) {
|
|
|
68
70
|
return fn(...args);
|
|
69
71
|
};
|
|
70
72
|
}
|
|
73
|
+
function isAdmin() {
|
|
74
|
+
if (import_node_process.default.platform === "win32") {
|
|
75
|
+
try {
|
|
76
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
77
|
+
return true;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
|
|
72
86
|
// src/caddy/index.ts
|
|
73
87
|
var import_node_os = require("os");
|
|
74
|
-
var
|
|
88
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
75
89
|
var import_node_fs = require("fs");
|
|
76
|
-
var
|
|
90
|
+
var import_node_child_process2 = require("child_process");
|
|
77
91
|
var import_got_cjs = require("got-cjs");
|
|
78
92
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
79
93
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
@@ -82,9 +96,9 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
82
96
|
|
|
83
97
|
// src/caddy/constants.ts
|
|
84
98
|
var import_node_path = require("path");
|
|
85
|
-
var
|
|
86
|
-
var TEMP_DIR =
|
|
87
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${
|
|
99
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
100
|
+
var TEMP_DIR = import_node_process2.default.env.TEMP || import_node_process2.default.env.TMPDIR || "/tmp";
|
|
101
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process2.default.platform === "win32" ? ".exe" : ""}`);
|
|
88
102
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
89
103
|
var supportList = [
|
|
90
104
|
{
|
|
@@ -261,15 +275,15 @@ async function download() {
|
|
|
261
275
|
const file = (0, import_node_fs.createWriteStream)(caddyPath);
|
|
262
276
|
let _platform = (0, import_node_os.platform)().toString();
|
|
263
277
|
_platform === "win32" && (_platform = "windows");
|
|
264
|
-
let _arch =
|
|
278
|
+
let _arch = import_node_process3.default.arch.toString();
|
|
265
279
|
_arch === "x64" && (_arch = "amd64");
|
|
266
280
|
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
267
281
|
if (!support)
|
|
268
282
|
return reject(new Error("not support"));
|
|
269
283
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
|
|
270
284
|
(0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
|
|
271
|
-
const httpProxy =
|
|
272
|
-
const httpsProxy =
|
|
285
|
+
const httpProxy = import_node_process3.default.env.HTTP_PROXY || import_node_process3.default.env.http_proxy;
|
|
286
|
+
const httpsProxy = import_node_process3.default.env.HTTPS_PROXY || import_node_process3.default.env.https_proxy;
|
|
273
287
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
274
288
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
275
289
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
@@ -281,7 +295,7 @@ async function download() {
|
|
|
281
295
|
logProgress(progress.percent);
|
|
282
296
|
}).pipe(file).on("finish", () => {
|
|
283
297
|
logProgressOver();
|
|
284
|
-
if (
|
|
298
|
+
if (import_node_process3.default.platform === "win32")
|
|
285
299
|
return resolve(caddyPath);
|
|
286
300
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
287
301
|
resolve(caddyPath);
|
|
@@ -295,7 +309,7 @@ function testCaddy() {
|
|
|
295
309
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
296
310
|
return resolve(false);
|
|
297
311
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
298
|
-
const child =
|
|
312
|
+
const child = import_node_process3.default.platform === "win32" ? (0, import_node_child_process2.spawn)(caddyPath, []) : (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath]);
|
|
299
313
|
child.on("close", () => {
|
|
300
314
|
return resolve(false);
|
|
301
315
|
});
|
|
@@ -326,15 +340,15 @@ var CaddyInstant = class {
|
|
|
326
340
|
this.host.add(ip, host);
|
|
327
341
|
await this.host.updateFinish();
|
|
328
342
|
return new Promise((resolve, reject) => {
|
|
329
|
-
if (
|
|
330
|
-
(0,
|
|
343
|
+
if (import_node_process3.default.platform === "win32") {
|
|
344
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
331
345
|
consola.error(err);
|
|
332
346
|
return resolve(false);
|
|
333
347
|
}).on("close", () => {
|
|
334
348
|
resolve(true);
|
|
335
349
|
});
|
|
336
350
|
} else {
|
|
337
|
-
(0,
|
|
351
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
338
352
|
consola.error(err);
|
|
339
353
|
return resolve(false);
|
|
340
354
|
}).on("close", () => {
|
|
@@ -348,15 +362,15 @@ var CaddyInstant = class {
|
|
|
348
362
|
this.host.remove(ip, host);
|
|
349
363
|
await this.host.updateFinish();
|
|
350
364
|
return new Promise((resolve, reject) => {
|
|
351
|
-
if (
|
|
352
|
-
(0,
|
|
365
|
+
if (import_node_process3.default.platform === "win32") {
|
|
366
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
353
367
|
consola.error(err);
|
|
354
368
|
return resolve(false);
|
|
355
369
|
}).on("close", () => {
|
|
356
370
|
resolve(true);
|
|
357
371
|
});
|
|
358
372
|
} else {
|
|
359
|
-
(0,
|
|
373
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
360
374
|
consola.error(err);
|
|
361
375
|
return resolve(false);
|
|
362
376
|
}).on("close", () => {
|
|
@@ -382,13 +396,13 @@ var CaddyInstant = class {
|
|
|
382
396
|
await this.init();
|
|
383
397
|
if (https && await tryPort(443))
|
|
384
398
|
await (0, import_kill_port.default)(443, "tcp");
|
|
385
|
-
if ((
|
|
399
|
+
if ((import_node_process3.default.platform === "win32" || !https) && await tryPort(80))
|
|
386
400
|
await (0, import_kill_port.default)(80, "tcp");
|
|
387
401
|
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
388
402
|
throw new Error("update host failed");
|
|
389
403
|
consola.success("update host success\n");
|
|
390
404
|
return new Promise((resolve, reject) => {
|
|
391
|
-
const child =
|
|
405
|
+
const child = import_node_process3.default.platform !== "win32" ? (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}${https ? "" : ":80"}`, "--to", `${source}`, "--internal-certs", "--insecure", "--disable-redirects"]) : (0, import_node_child_process2.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
392
406
|
child.on("error", (err) => {
|
|
393
407
|
return reject(err);
|
|
394
408
|
});
|
|
@@ -431,30 +445,30 @@ var caddy;
|
|
|
431
445
|
var _stop;
|
|
432
446
|
var _servce;
|
|
433
447
|
function registerExit(clear) {
|
|
434
|
-
|
|
448
|
+
import_node_process4.default.on("beforeExit", async (_code) => {
|
|
435
449
|
await clear();
|
|
436
450
|
});
|
|
437
|
-
|
|
451
|
+
import_node_process4.default.on("uncaughtException", async (err) => {
|
|
438
452
|
console.error("An uncaught error occurred!", err.stack);
|
|
439
453
|
await clear();
|
|
440
|
-
|
|
441
|
-
|
|
454
|
+
import_node_process4.default.nextTick(() => {
|
|
455
|
+
import_node_process4.default.exit(1);
|
|
442
456
|
});
|
|
443
457
|
});
|
|
444
|
-
|
|
458
|
+
import_node_process4.default.on("unhandledRejection", async (reason, promise) => {
|
|
445
459
|
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
446
460
|
await clear();
|
|
447
|
-
|
|
448
|
-
|
|
461
|
+
import_node_process4.default.nextTick(() => {
|
|
462
|
+
import_node_process4.default.exit(1);
|
|
449
463
|
});
|
|
450
464
|
});
|
|
451
|
-
|
|
465
|
+
import_node_process4.default.once("SIGINT", async () => {
|
|
452
466
|
await clear();
|
|
453
|
-
|
|
467
|
+
import_node_process4.default.exit(0);
|
|
454
468
|
});
|
|
455
|
-
|
|
469
|
+
import_node_process4.default.once("SIGTERM", async () => {
|
|
456
470
|
await clear();
|
|
457
|
-
|
|
471
|
+
import_node_process4.default.exit(0);
|
|
458
472
|
});
|
|
459
473
|
}
|
|
460
474
|
var unpluginFactory = (options) => ({
|
|
@@ -479,6 +493,10 @@ var unpluginFactory = (options) => ({
|
|
|
479
493
|
});
|
|
480
494
|
},
|
|
481
495
|
configureServer(server) {
|
|
496
|
+
if (!isAdmin()) {
|
|
497
|
+
consola.warn("please run as administrator");
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
482
500
|
if (config.command === "build")
|
|
483
501
|
return;
|
|
484
502
|
const {
|
|
@@ -496,9 +514,10 @@ var unpluginFactory = (options) => ({
|
|
|
496
514
|
server.printUrls = () => {
|
|
497
515
|
var _a;
|
|
498
516
|
_printUrls();
|
|
499
|
-
const pwd =
|
|
517
|
+
const pwd = import_node_process4.default.cwd();
|
|
500
518
|
const vireCacheDir = `${pwd}/node_modules/.vite`;
|
|
501
|
-
(0, import_node_fs2.
|
|
519
|
+
if ((0, import_node_fs2.existsSync)(vireCacheDir))
|
|
520
|
+
(0, import_node_fs2.chmodSync)(vireCacheDir, 511);
|
|
502
521
|
let source = `localhost:${config.server.port}`;
|
|
503
522
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
504
523
|
if (url) {
|
|
@@ -526,7 +545,11 @@ var unpluginFactory = (options) => ({
|
|
|
526
545
|
}
|
|
527
546
|
},
|
|
528
547
|
webpack(compiler) {
|
|
529
|
-
if (
|
|
548
|
+
if (!isAdmin()) {
|
|
549
|
+
consola.warn("please run as administrator");
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (import_node_process4.default.env.NODE_ENV !== "development")
|
|
530
553
|
return;
|
|
531
554
|
const {
|
|
532
555
|
enable = true,
|
|
@@ -542,7 +565,7 @@ var unpluginFactory = (options) => ({
|
|
|
542
565
|
const devServer = __spreadValues(__spreadValues({
|
|
543
566
|
host: "localhost",
|
|
544
567
|
port: 8080
|
|
545
|
-
}, compiler.options.devServer),
|
|
568
|
+
}, compiler.options.devServer), import_node_process4.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
546
569
|
const source = `${devServer.host}:${devServer.port}`;
|
|
547
570
|
if (caddy)
|
|
548
571
|
return;
|
|
@@ -554,7 +577,7 @@ var unpluginFactory = (options) => ({
|
|
|
554
577
|
});
|
|
555
578
|
} catch (e) {
|
|
556
579
|
consola.error(e);
|
|
557
|
-
|
|
580
|
+
import_node_process4.default.exit(1);
|
|
558
581
|
}
|
|
559
582
|
};
|
|
560
583
|
caddy = new CaddyInstant();
|