unplugin-https-reverse-proxy 0.0.20 → 0.0.22
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-5MGNE7J4.js} +1 -1
- package/dist/{chunk-KYPQLMHO.js → chunk-BTWCTT26.js} +35 -14
- package/dist/{chunk-CQC5SSJR.js → chunk-NNO3ZUSU.js} +16 -1
- package/dist/{chunk-VXVYW4ZE.js → chunk-Q7NSASV3.js} +1 -1
- package/dist/esbuild.cjs +79 -45
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +79 -45
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +79 -45
- package/dist/nuxt.js +4 -4
- package/dist/rollup.cjs +79 -45
- 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 +79 -45
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +79 -45
- package/dist/webpack.js +3 -3
- package/package.json +2 -1
- package/src/index.ts +36 -22
- 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,11 @@ var unpluginFactory = (options) => ({
|
|
|
467
473
|
}
|
|
468
474
|
},
|
|
469
475
|
webpack(compiler) {
|
|
476
|
+
var _a;
|
|
477
|
+
if (!isAdmin()) {
|
|
478
|
+
consola.warn("please run as administrator");
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
470
481
|
if (process3.env.NODE_ENV !== "development")
|
|
471
482
|
return;
|
|
472
483
|
const {
|
|
@@ -487,17 +498,27 @@ var unpluginFactory = (options) => ({
|
|
|
487
498
|
const source = `${devServer.host}:${devServer.port}`;
|
|
488
499
|
if (caddy)
|
|
489
500
|
return;
|
|
490
|
-
const _close = compiler.close.bind(compiler);
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
+
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
502
|
+
if (_close) {
|
|
503
|
+
compiler.close = async (callback) => {
|
|
504
|
+
try {
|
|
505
|
+
_stop && await _stop(() => {
|
|
506
|
+
_close && _close(callback);
|
|
507
|
+
});
|
|
508
|
+
} catch (e) {
|
|
509
|
+
consola.error(e);
|
|
510
|
+
process3.exit(1);
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
} else {
|
|
514
|
+
registerExit(async () => {
|
|
515
|
+
try {
|
|
516
|
+
_stop && await _stop();
|
|
517
|
+
} catch (e) {
|
|
518
|
+
consola.error(e);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
}
|
|
501
522
|
caddy = new CaddyInstant();
|
|
502
523
|
caddy.run(source, target, __spreadValues({}, options)).then((stop) => {
|
|
503
524
|
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
@@ -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,12 @@ var unpluginFactory = (options) => ({
|
|
|
527
546
|
}
|
|
528
547
|
},
|
|
529
548
|
webpack(compiler) {
|
|
530
|
-
|
|
549
|
+
var _a;
|
|
550
|
+
if (!isAdmin()) {
|
|
551
|
+
consola.warn("please run as administrator");
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (import_node_process4.default.env.NODE_ENV !== "development")
|
|
531
555
|
return;
|
|
532
556
|
const {
|
|
533
557
|
enable = true,
|
|
@@ -543,21 +567,31 @@ var unpluginFactory = (options) => ({
|
|
|
543
567
|
const devServer = __spreadValues(__spreadValues({
|
|
544
568
|
host: "localhost",
|
|
545
569
|
port: 8080
|
|
546
|
-
}, compiler.options.devServer),
|
|
570
|
+
}, compiler.options.devServer), import_node_process4.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
547
571
|
const source = `${devServer.host}:${devServer.port}`;
|
|
548
572
|
if (caddy)
|
|
549
573
|
return;
|
|
550
|
-
const _close = compiler.close.bind(compiler);
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
574
|
+
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
575
|
+
if (_close) {
|
|
576
|
+
compiler.close = async (callback) => {
|
|
577
|
+
try {
|
|
578
|
+
_stop && await _stop(() => {
|
|
579
|
+
_close && _close(callback);
|
|
580
|
+
});
|
|
581
|
+
} catch (e) {
|
|
582
|
+
consola.error(e);
|
|
583
|
+
import_node_process4.default.exit(1);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
} else {
|
|
587
|
+
registerExit(async () => {
|
|
588
|
+
try {
|
|
589
|
+
_stop && await _stop();
|
|
590
|
+
} catch (e) {
|
|
591
|
+
consola.error(e);
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
561
595
|
caddy = new CaddyInstant();
|
|
562
596
|
caddy.run(source, target, __spreadValues({}, options)).then((stop) => {
|
|
563
597
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|