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
package/dist/nuxt.cjs
CHANGED
|
@@ -53,12 +53,14 @@ var import_kit = require("@nuxt/kit");
|
|
|
53
53
|
var import_unplugin2 = require("unplugin");
|
|
54
54
|
|
|
55
55
|
// src/index.ts
|
|
56
|
-
var
|
|
56
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
57
57
|
var import_node_fs2 = require("fs");
|
|
58
58
|
var import_unplugin = require("unplugin");
|
|
59
59
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
60
60
|
|
|
61
61
|
// src/utils.ts
|
|
62
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
63
|
+
var import_node_child_process = require("child_process");
|
|
62
64
|
var import_consola = require("consola");
|
|
63
65
|
var consola = (0, import_consola.createConsola)({
|
|
64
66
|
level: 3
|
|
@@ -72,12 +74,24 @@ function once(fn) {
|
|
|
72
74
|
return fn(...args);
|
|
73
75
|
};
|
|
74
76
|
}
|
|
77
|
+
function isAdmin() {
|
|
78
|
+
if (import_node_process.default.platform === "win32") {
|
|
79
|
+
try {
|
|
80
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
81
|
+
return true;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
75
89
|
|
|
76
90
|
// src/caddy/index.ts
|
|
77
91
|
var import_node_os = require("os");
|
|
78
|
-
var
|
|
92
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
79
93
|
var import_node_fs = require("fs");
|
|
80
|
-
var
|
|
94
|
+
var import_node_child_process2 = require("child_process");
|
|
81
95
|
var import_got_cjs = require("got-cjs");
|
|
82
96
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
83
97
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
@@ -86,9 +100,9 @@ var import_kill_port = __toESM(require("kill-port"), 1);
|
|
|
86
100
|
|
|
87
101
|
// src/caddy/constants.ts
|
|
88
102
|
var import_node_path = require("path");
|
|
89
|
-
var
|
|
90
|
-
var TEMP_DIR =
|
|
91
|
-
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${
|
|
103
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
104
|
+
var TEMP_DIR = import_node_process2.default.env.TEMP || import_node_process2.default.env.TMPDIR || "/tmp";
|
|
105
|
+
var caddyPath = (0, import_node_path.join)(TEMP_DIR, `caddy${import_node_process2.default.platform === "win32" ? ".exe" : ""}`);
|
|
92
106
|
var caddyFilePath = (0, import_node_path.join)(TEMP_DIR, "CADDYFILE");
|
|
93
107
|
var supportList = [
|
|
94
108
|
{
|
|
@@ -265,15 +279,15 @@ async function download() {
|
|
|
265
279
|
const file = (0, import_node_fs.createWriteStream)(caddyPath);
|
|
266
280
|
let _platform = (0, import_node_os.platform)().toString();
|
|
267
281
|
_platform === "win32" && (_platform = "windows");
|
|
268
|
-
let _arch =
|
|
282
|
+
let _arch = import_node_process3.default.arch.toString();
|
|
269
283
|
_arch === "x64" && (_arch = "amd64");
|
|
270
284
|
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
271
285
|
if (!support)
|
|
272
286
|
return reject(new Error("not support"));
|
|
273
287
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
|
|
274
288
|
(0, import_node_fs.existsSync)(caddyPath) && (0, import_node_fs.unlinkSync)(caddyPath);
|
|
275
|
-
const httpProxy =
|
|
276
|
-
const httpsProxy =
|
|
289
|
+
const httpProxy = import_node_process3.default.env.HTTP_PROXY || import_node_process3.default.env.http_proxy;
|
|
290
|
+
const httpsProxy = import_node_process3.default.env.HTTPS_PROXY || import_node_process3.default.env.https_proxy;
|
|
277
291
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
278
292
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
279
293
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
@@ -285,7 +299,7 @@ async function download() {
|
|
|
285
299
|
logProgress(progress.percent);
|
|
286
300
|
}).pipe(file).on("finish", () => {
|
|
287
301
|
logProgressOver();
|
|
288
|
-
if (
|
|
302
|
+
if (import_node_process3.default.platform === "win32")
|
|
289
303
|
return resolve(caddyPath);
|
|
290
304
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
291
305
|
resolve(caddyPath);
|
|
@@ -299,7 +313,7 @@ function testCaddy() {
|
|
|
299
313
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
300
314
|
return resolve(false);
|
|
301
315
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
302
|
-
const child =
|
|
316
|
+
const child = import_node_process3.default.platform === "win32" ? (0, import_node_child_process2.spawn)(caddyPath, []) : (0, import_node_child_process2.spawn)("sudo", ["-E", caddyPath]);
|
|
303
317
|
child.on("close", () => {
|
|
304
318
|
return resolve(false);
|
|
305
319
|
});
|
|
@@ -330,15 +344,15 @@ var CaddyInstant = class {
|
|
|
330
344
|
this.host.add(ip, host);
|
|
331
345
|
await this.host.updateFinish();
|
|
332
346
|
return new Promise((resolve, reject) => {
|
|
333
|
-
if (
|
|
334
|
-
(0,
|
|
347
|
+
if (import_node_process3.default.platform === "win32") {
|
|
348
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
335
349
|
consola.error(err);
|
|
336
350
|
return resolve(false);
|
|
337
351
|
}).on("close", () => {
|
|
338
352
|
resolve(true);
|
|
339
353
|
});
|
|
340
354
|
} else {
|
|
341
|
-
(0,
|
|
355
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
342
356
|
consola.error(err);
|
|
343
357
|
return resolve(false);
|
|
344
358
|
}).on("close", () => {
|
|
@@ -352,15 +366,15 @@ var CaddyInstant = class {
|
|
|
352
366
|
this.host.remove(ip, host);
|
|
353
367
|
await this.host.updateFinish();
|
|
354
368
|
return new Promise((resolve, reject) => {
|
|
355
|
-
if (
|
|
356
|
-
(0,
|
|
369
|
+
if (import_node_process3.default.platform === "win32") {
|
|
370
|
+
(0, import_node_child_process2.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
357
371
|
consola.error(err);
|
|
358
372
|
return resolve(false);
|
|
359
373
|
}).on("close", () => {
|
|
360
374
|
resolve(true);
|
|
361
375
|
});
|
|
362
376
|
} else {
|
|
363
|
-
(0,
|
|
377
|
+
(0, import_node_child_process2.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
364
378
|
consola.error(err);
|
|
365
379
|
return resolve(false);
|
|
366
380
|
}).on("close", () => {
|
|
@@ -386,13 +400,13 @@ var CaddyInstant = class {
|
|
|
386
400
|
await this.init();
|
|
387
401
|
if (https && await tryPort(443))
|
|
388
402
|
await (0, import_kill_port.default)(443, "tcp");
|
|
389
|
-
if ((
|
|
403
|
+
if ((import_node_process3.default.platform === "win32" || !https) && await tryPort(80))
|
|
390
404
|
await (0, import_kill_port.default)(80, "tcp");
|
|
391
405
|
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
392
406
|
throw new Error("update host failed");
|
|
393
407
|
consola.success("update host success\n");
|
|
394
408
|
return new Promise((resolve, reject) => {
|
|
395
|
-
const child =
|
|
409
|
+
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"]);
|
|
396
410
|
child.on("error", (err) => {
|
|
397
411
|
return reject(err);
|
|
398
412
|
});
|
|
@@ -435,30 +449,30 @@ var caddy;
|
|
|
435
449
|
var _stop;
|
|
436
450
|
var _servce;
|
|
437
451
|
function registerExit(clear) {
|
|
438
|
-
|
|
452
|
+
import_node_process4.default.on("beforeExit", async (_code) => {
|
|
439
453
|
await clear();
|
|
440
454
|
});
|
|
441
|
-
|
|
455
|
+
import_node_process4.default.on("uncaughtException", async (err) => {
|
|
442
456
|
console.error("An uncaught error occurred!", err.stack);
|
|
443
457
|
await clear();
|
|
444
|
-
|
|
445
|
-
|
|
458
|
+
import_node_process4.default.nextTick(() => {
|
|
459
|
+
import_node_process4.default.exit(1);
|
|
446
460
|
});
|
|
447
461
|
});
|
|
448
|
-
|
|
462
|
+
import_node_process4.default.on("unhandledRejection", async (reason, promise) => {
|
|
449
463
|
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
450
464
|
await clear();
|
|
451
|
-
|
|
452
|
-
|
|
465
|
+
import_node_process4.default.nextTick(() => {
|
|
466
|
+
import_node_process4.default.exit(1);
|
|
453
467
|
});
|
|
454
468
|
});
|
|
455
|
-
|
|
469
|
+
import_node_process4.default.once("SIGINT", async () => {
|
|
456
470
|
await clear();
|
|
457
|
-
|
|
471
|
+
import_node_process4.default.exit(0);
|
|
458
472
|
});
|
|
459
|
-
|
|
473
|
+
import_node_process4.default.once("SIGTERM", async () => {
|
|
460
474
|
await clear();
|
|
461
|
-
|
|
475
|
+
import_node_process4.default.exit(0);
|
|
462
476
|
});
|
|
463
477
|
}
|
|
464
478
|
var unpluginFactory = (options) => ({
|
|
@@ -483,6 +497,10 @@ var unpluginFactory = (options) => ({
|
|
|
483
497
|
});
|
|
484
498
|
},
|
|
485
499
|
configureServer(server) {
|
|
500
|
+
if (!isAdmin()) {
|
|
501
|
+
consola.warn("please run as administrator");
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
486
504
|
if (config.command === "build")
|
|
487
505
|
return;
|
|
488
506
|
const {
|
|
@@ -500,9 +518,10 @@ var unpluginFactory = (options) => ({
|
|
|
500
518
|
server.printUrls = () => {
|
|
501
519
|
var _a;
|
|
502
520
|
_printUrls();
|
|
503
|
-
const pwd =
|
|
521
|
+
const pwd = import_node_process4.default.cwd();
|
|
504
522
|
const vireCacheDir = `${pwd}/node_modules/.vite`;
|
|
505
|
-
(0, import_node_fs2.
|
|
523
|
+
if ((0, import_node_fs2.existsSync)(vireCacheDir))
|
|
524
|
+
(0, import_node_fs2.chmodSync)(vireCacheDir, 511);
|
|
506
525
|
let source = `localhost:${config.server.port}`;
|
|
507
526
|
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
508
527
|
if (url) {
|
|
@@ -530,7 +549,11 @@ var unpluginFactory = (options) => ({
|
|
|
530
549
|
}
|
|
531
550
|
},
|
|
532
551
|
webpack(compiler) {
|
|
533
|
-
if (
|
|
552
|
+
if (!isAdmin()) {
|
|
553
|
+
consola.warn("please run as administrator");
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (import_node_process4.default.env.NODE_ENV !== "development")
|
|
534
557
|
return;
|
|
535
558
|
const {
|
|
536
559
|
enable = true,
|
|
@@ -546,7 +569,7 @@ var unpluginFactory = (options) => ({
|
|
|
546
569
|
const devServer = __spreadValues(__spreadValues({
|
|
547
570
|
host: "localhost",
|
|
548
571
|
port: 8080
|
|
549
|
-
}, compiler.options.devServer),
|
|
572
|
+
}, compiler.options.devServer), import_node_process4.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
550
573
|
const source = `${devServer.host}:${devServer.port}`;
|
|
551
574
|
if (caddy)
|
|
552
575
|
return;
|
|
@@ -558,7 +581,7 @@ var unpluginFactory = (options) => ({
|
|
|
558
581
|
});
|
|
559
582
|
} catch (e) {
|
|
560
583
|
consola.error(e);
|
|
561
|
-
|
|
584
|
+
import_node_process4.default.exit(1);
|
|
562
585
|
}
|
|
563
586
|
};
|
|
564
587
|
caddy = new CaddyInstant();
|
package/dist/nuxt.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3M3YENXO.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-CT3M7EPZ.js";
|
|
7
|
+
import "./chunk-NH3VM3RE.js";
|
|
8
|
+
import "./chunk-NNO3ZUSU.js";
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
|
11
11
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
package/dist/rollup.cjs
CHANGED
|
@@ -50,12 +50,14 @@ module.exports = __toCommonJS(rollup_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/rollup.js
CHANGED
package/dist/utils.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,15 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/utils.ts
|
|
21
31
|
var utils_exports = {};
|
|
22
32
|
__export(utils_exports, {
|
|
23
33
|
consola: () => consola,
|
|
34
|
+
isAdmin: () => isAdmin,
|
|
24
35
|
once: () => once
|
|
25
36
|
});
|
|
26
37
|
module.exports = __toCommonJS(utils_exports);
|
|
38
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
39
|
+
var import_node_child_process = require("child_process");
|
|
27
40
|
var import_consola = require("consola");
|
|
28
41
|
var consola = (0, import_consola.createConsola)({
|
|
29
42
|
level: 3
|
|
@@ -37,9 +50,22 @@ function once(fn) {
|
|
|
37
50
|
return fn(...args);
|
|
38
51
|
};
|
|
39
52
|
}
|
|
53
|
+
function isAdmin() {
|
|
54
|
+
if (import_node_process.default.platform === "win32") {
|
|
55
|
+
try {
|
|
56
|
+
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
57
|
+
return true;
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
return import_node_process.default.getuid && import_node_process.default.getuid() === 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
40
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
41
66
|
0 && (module.exports = {
|
|
42
67
|
consola,
|
|
68
|
+
isAdmin,
|
|
43
69
|
once
|
|
44
70
|
});
|
|
45
71
|
exports.default = module.exports;
|
package/dist/utils.d.cts
CHANGED
|
@@ -2,5 +2,6 @@ import * as consola_dist_core from 'consola/dist/core';
|
|
|
2
2
|
|
|
3
3
|
declare const consola: consola_dist_core.ConsolaInstance;
|
|
4
4
|
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
5
|
+
declare function isAdmin(): boolean | undefined;
|
|
5
6
|
|
|
6
|
-
export { consola, once };
|
|
7
|
+
export { consola, isAdmin, once };
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import * as consola_dist_core from 'consola/dist/core';
|
|
|
2
2
|
|
|
3
3
|
declare const consola: consola_dist_core.ConsolaInstance;
|
|
4
4
|
declare function once<T extends (...args: any[]) => any>(fn: T): (...args: Parameters<T>) => ReturnType<T>;
|
|
5
|
+
declare function isAdmin(): boolean | undefined;
|
|
5
6
|
|
|
6
|
-
export { consola, once };
|
|
7
|
+
export { consola, isAdmin, once };
|