unplugin-https-reverse-proxy 1.0.0-beta.1 → 1.0.0-beta.10
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 +94 -1
- package/dist/{chunk-NNO3ZUSU.js → chunk-RUJE3YFB.js} +11 -0
- package/dist/{chunk-DUCXH7CX.js → chunk-XLSIGDFU.js} +121 -68
- package/dist/esbuild.cjs +140 -70
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +140 -70
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +85 -144
- package/dist/nuxt.js +24 -22
- package/dist/rollup.cjs +140 -70
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +643 -0
- package/dist/rspack.d.cts +5 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.js +10 -0
- package/dist/utils.cjs +12 -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 +140 -70
- package/dist/vite.d.cts +1 -2
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +7 -4
- package/dist/webpack.cjs +140 -70
- package/dist/webpack.js +7 -4
- package/package.json +41 -24
- package/src/caddy/constants.ts +13 -1
- package/src/caddy/index.ts +32 -5
- package/src/index.ts +111 -79
- package/src/nuxt.ts +26 -19
- package/src/rspack.ts +5 -0
- package/src/utils.ts +11 -0
- package/dist/chunk-QIKJQBZH.js +0 -11
- package/dist/chunk-Y5ZVZOMP.js +0 -11
package/dist/esbuild.cjs
CHANGED
|
@@ -51,17 +51,35 @@ var import_unplugin2 = require("unplugin");
|
|
|
51
51
|
|
|
52
52
|
// src/index.ts
|
|
53
53
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
54
|
-
var import_node_fs3 = require("fs");
|
|
55
54
|
var import_unplugin = require("unplugin");
|
|
56
55
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
56
|
|
|
58
57
|
// src/utils.ts
|
|
59
58
|
var import_node_process = __toESM(require("process"), 1);
|
|
59
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
60
|
+
var import_promises = require("fs/promises");
|
|
60
61
|
var import_node_child_process = require("child_process");
|
|
61
62
|
var import_consola = require("consola");
|
|
62
63
|
var consola = (0, import_consola.createConsola)({
|
|
63
64
|
level: 3
|
|
64
65
|
}).withTag("reverse-proxy");
|
|
66
|
+
async function chmodRecursive(_path, mode) {
|
|
67
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
68
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
69
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
70
|
+
for (const child of children)
|
|
71
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function once(fn) {
|
|
75
|
+
let called = false;
|
|
76
|
+
return (...args) => {
|
|
77
|
+
if (called)
|
|
78
|
+
return;
|
|
79
|
+
called = true;
|
|
80
|
+
return fn(...args);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
65
83
|
function isAdmin() {
|
|
66
84
|
if (import_node_process.default.platform === "win32") {
|
|
67
85
|
try {
|
|
@@ -76,7 +94,7 @@ function isAdmin() {
|
|
|
76
94
|
}
|
|
77
95
|
|
|
78
96
|
// src/caddy/index.ts
|
|
79
|
-
var
|
|
97
|
+
var import_node_os2 = require("os");
|
|
80
98
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
81
99
|
var import_node_fs2 = require("fs");
|
|
82
100
|
var import_node_child_process3 = require("child_process");
|
|
@@ -133,11 +151,21 @@ async function removeHost(ip, host) {
|
|
|
133
151
|
}
|
|
134
152
|
|
|
135
153
|
// src/caddy/constants.ts
|
|
136
|
-
var
|
|
154
|
+
var import_node_path2 = require("path");
|
|
155
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
137
156
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
158
|
+
import_dotenv_flow.default.config({
|
|
159
|
+
silent: true
|
|
160
|
+
});
|
|
161
|
+
function resolvePath(path2) {
|
|
162
|
+
if (path2.startsWith("~"))
|
|
163
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
164
|
+
return path2;
|
|
165
|
+
}
|
|
166
|
+
var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
|
|
167
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
168
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
141
169
|
var supportList = [
|
|
142
170
|
{
|
|
143
171
|
platform: "dragonfly",
|
|
@@ -309,8 +337,12 @@ async function download() {
|
|
|
309
337
|
if (await testCaddy())
|
|
310
338
|
return caddyPath;
|
|
311
339
|
return new Promise((resolve, reject) => {
|
|
340
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
341
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
342
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
343
|
+
}
|
|
312
344
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
313
|
-
let _platform = (0,
|
|
345
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
314
346
|
_platform === "win32" && (_platform = "windows");
|
|
315
347
|
let _arch = import_node_process4.default.arch.toString();
|
|
316
348
|
_arch === "x64" && (_arch = "amd64");
|
|
@@ -323,6 +355,9 @@ async function download() {
|
|
|
323
355
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
324
356
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
325
357
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
358
|
+
const chmodCaddyOnce = once(() => {
|
|
359
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
360
|
+
});
|
|
326
361
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
327
362
|
agent: {
|
|
328
363
|
http: httpAgent,
|
|
@@ -330,11 +365,12 @@ async function download() {
|
|
|
330
365
|
}
|
|
331
366
|
}).on("downloadProgress", (progress) => {
|
|
332
367
|
logProgress(progress.percent);
|
|
368
|
+
chmodCaddyOnce();
|
|
333
369
|
}).pipe(file).on("finish", () => {
|
|
334
370
|
logProgressOver();
|
|
335
371
|
if (import_node_process4.default.platform === "win32")
|
|
336
372
|
return resolve(caddyPath);
|
|
337
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
373
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
338
374
|
resolve(caddyPath);
|
|
339
375
|
}).on("error", (err) => {
|
|
340
376
|
reject(err);
|
|
@@ -345,7 +381,7 @@ function testCaddy() {
|
|
|
345
381
|
return new Promise((resolve, reject) => {
|
|
346
382
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
347
383
|
return resolve(false);
|
|
348
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
384
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
349
385
|
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process3.spawn)(caddyPath, []) : (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath]);
|
|
350
386
|
child.on("close", () => {
|
|
351
387
|
return resolve(false);
|
|
@@ -417,6 +453,19 @@ var CaddyInstant = class {
|
|
|
417
453
|
});
|
|
418
454
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
419
455
|
import_node_process4.default.exit = async (code) => {
|
|
456
|
+
const port = Number(source.split(":")[1]);
|
|
457
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
458
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
459
|
+
const pwd = import_node_process4.default.cwd();
|
|
460
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
461
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
462
|
+
chmodRecursive(viteCacheDir, 511);
|
|
463
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
464
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
465
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
466
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
467
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
468
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
420
469
|
if (!restore || this.stoped)
|
|
421
470
|
return originalExit(code);
|
|
422
471
|
try {
|
|
@@ -455,31 +504,21 @@ var CaddyInstant = class {
|
|
|
455
504
|
// src/index.ts
|
|
456
505
|
var config;
|
|
457
506
|
var caddy;
|
|
458
|
-
|
|
507
|
+
var cwd = import_node_process5.default.cwd();
|
|
508
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
459
509
|
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
base
|
|
473
|
-
}, options)).then(() => {
|
|
474
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
-
}).catch((e) => {
|
|
477
|
-
throw e;
|
|
478
|
-
});
|
|
479
|
-
} catch (e) {
|
|
480
|
-
consola.error(e);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
510
|
+
if (caddy)
|
|
511
|
+
return;
|
|
512
|
+
caddy = new CaddyInstant();
|
|
513
|
+
caddy.run(source, target, __spreadValues({
|
|
514
|
+
base
|
|
515
|
+
}, options)).then(() => {
|
|
516
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
517
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
518
|
+
}).catch((e) => {
|
|
519
|
+
throw e;
|
|
520
|
+
});
|
|
521
|
+
});
|
|
483
522
|
var unpluginFactory = (options) => ({
|
|
484
523
|
name: "unplugin-https-reverse-proxy",
|
|
485
524
|
enforce: "pre",
|
|
@@ -489,11 +528,7 @@ var unpluginFactory = (options) => ({
|
|
|
489
528
|
},
|
|
490
529
|
configureServer(server) {
|
|
491
530
|
var _a;
|
|
492
|
-
if (
|
|
493
|
-
consola.warn("please run as administrator");
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
if (config.command === "build")
|
|
531
|
+
if (config.command !== "serve")
|
|
497
532
|
return;
|
|
498
533
|
const {
|
|
499
534
|
enable = true,
|
|
@@ -501,6 +536,10 @@ var unpluginFactory = (options) => ({
|
|
|
501
536
|
} = options;
|
|
502
537
|
if (!enable)
|
|
503
538
|
return;
|
|
539
|
+
if (!isAdmin()) {
|
|
540
|
+
consola.warn("please run as administrator");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
504
543
|
if (!target) {
|
|
505
544
|
consola.fail("please provide target");
|
|
506
545
|
return;
|
|
@@ -513,15 +552,56 @@ var unpluginFactory = (options) => ({
|
|
|
513
552
|
source = u.host;
|
|
514
553
|
}
|
|
515
554
|
const base = server.config.base || "/";
|
|
516
|
-
server.printUrls = () => vitePrintUrls(
|
|
555
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
517
556
|
}
|
|
518
557
|
},
|
|
519
558
|
webpack(compiler) {
|
|
520
|
-
var _a;
|
|
559
|
+
var _a, _b;
|
|
560
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
561
|
+
return;
|
|
562
|
+
const {
|
|
563
|
+
enable = true,
|
|
564
|
+
target = ""
|
|
565
|
+
} = options;
|
|
566
|
+
if (!enable)
|
|
567
|
+
return;
|
|
521
568
|
if (!isAdmin()) {
|
|
522
569
|
consola.warn("please run as administrator");
|
|
523
570
|
return;
|
|
524
571
|
}
|
|
572
|
+
if (!target) {
|
|
573
|
+
consola.fail("please provide target");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const devServer = __spreadValues(__spreadValues({
|
|
577
|
+
host: "localhost",
|
|
578
|
+
port: 8080
|
|
579
|
+
}, compiler.options.devServer), (_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
|
|
580
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
581
|
+
if (caddy)
|
|
582
|
+
return;
|
|
583
|
+
const _close = (_b = compiler.close) == null ? void 0 : _b.bind(compiler);
|
|
584
|
+
if (_close) {
|
|
585
|
+
compiler.close = async (callback) => {
|
|
586
|
+
import_node_process5.default.on("exit", () => {
|
|
587
|
+
_close && _close(callback);
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
} else {
|
|
591
|
+
options.https = false;
|
|
592
|
+
}
|
|
593
|
+
caddy = new CaddyInstant();
|
|
594
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
595
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
596
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
597
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
598
|
+
});
|
|
599
|
+
}).catch((e) => {
|
|
600
|
+
throw e;
|
|
601
|
+
});
|
|
602
|
+
},
|
|
603
|
+
async rspack(compiler) {
|
|
604
|
+
var _a, _b, _c;
|
|
525
605
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
526
606
|
return;
|
|
527
607
|
const {
|
|
@@ -530,40 +610,30 @@ var unpluginFactory = (options) => ({
|
|
|
530
610
|
} = options;
|
|
531
611
|
if (!enable)
|
|
532
612
|
return;
|
|
613
|
+
if (!isAdmin()) {
|
|
614
|
+
consola.warn("please run as administrator");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
533
617
|
if (!target) {
|
|
534
618
|
consola.fail("please provide target");
|
|
535
619
|
return;
|
|
536
620
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
options.https = false;
|
|
554
|
-
}
|
|
555
|
-
caddy = new CaddyInstant();
|
|
556
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
557
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
558
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
559
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
560
|
-
});
|
|
561
|
-
}).catch((e) => {
|
|
562
|
-
throw e;
|
|
563
|
-
});
|
|
564
|
-
} catch (e) {
|
|
565
|
-
consola.error(e);
|
|
566
|
-
}
|
|
621
|
+
const devServer = __spreadValues(__spreadValues({
|
|
622
|
+
host: "localhost",
|
|
623
|
+
port: 8080
|
|
624
|
+
}, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
625
|
+
cwd
|
|
626
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
|
|
627
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
628
|
+
if (caddy)
|
|
629
|
+
return;
|
|
630
|
+
caddy = new CaddyInstant();
|
|
631
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
632
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
633
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
634
|
+
}).catch((e) => {
|
|
635
|
+
throw e;
|
|
636
|
+
});
|
|
567
637
|
}
|
|
568
638
|
});
|
|
569
639
|
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -51,17 +51,35 @@ __export(src_exports, {
|
|
|
51
51
|
});
|
|
52
52
|
module.exports = __toCommonJS(src_exports);
|
|
53
53
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
54
|
-
var import_node_fs3 = require("fs");
|
|
55
54
|
var import_unplugin = require("unplugin");
|
|
56
55
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
56
|
|
|
58
57
|
// src/utils.ts
|
|
59
58
|
var import_node_process = __toESM(require("process"), 1);
|
|
59
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
60
|
+
var import_promises = require("fs/promises");
|
|
60
61
|
var import_node_child_process = require("child_process");
|
|
61
62
|
var import_consola = require("consola");
|
|
62
63
|
var consola = (0, import_consola.createConsola)({
|
|
63
64
|
level: 3
|
|
64
65
|
}).withTag("reverse-proxy");
|
|
66
|
+
async function chmodRecursive(_path, mode) {
|
|
67
|
+
await (0, import_promises.chmod)(_path, mode);
|
|
68
|
+
if ((await (0, import_promises.stat)(_path)).isDirectory()) {
|
|
69
|
+
const children = await (0, import_promises.readdir)(_path);
|
|
70
|
+
for (const child of children)
|
|
71
|
+
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function once(fn) {
|
|
75
|
+
let called = false;
|
|
76
|
+
return (...args) => {
|
|
77
|
+
if (called)
|
|
78
|
+
return;
|
|
79
|
+
called = true;
|
|
80
|
+
return fn(...args);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
65
83
|
function isAdmin() {
|
|
66
84
|
if (import_node_process.default.platform === "win32") {
|
|
67
85
|
try {
|
|
@@ -76,7 +94,7 @@ function isAdmin() {
|
|
|
76
94
|
}
|
|
77
95
|
|
|
78
96
|
// src/caddy/index.ts
|
|
79
|
-
var
|
|
97
|
+
var import_node_os2 = require("os");
|
|
80
98
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
81
99
|
var import_node_fs2 = require("fs");
|
|
82
100
|
var import_node_child_process3 = require("child_process");
|
|
@@ -133,11 +151,21 @@ async function removeHost(ip, host) {
|
|
|
133
151
|
}
|
|
134
152
|
|
|
135
153
|
// src/caddy/constants.ts
|
|
136
|
-
var
|
|
154
|
+
var import_node_path2 = require("path");
|
|
155
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
137
156
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
157
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
158
|
+
import_dotenv_flow.default.config({
|
|
159
|
+
silent: true
|
|
160
|
+
});
|
|
161
|
+
function resolvePath(path2) {
|
|
162
|
+
if (path2.startsWith("~"))
|
|
163
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
164
|
+
return path2;
|
|
165
|
+
}
|
|
166
|
+
var TEMP_DIR = resolvePath(import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp");
|
|
167
|
+
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
168
|
+
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
141
169
|
var supportList = [
|
|
142
170
|
{
|
|
143
171
|
platform: "dragonfly",
|
|
@@ -309,8 +337,12 @@ async function download() {
|
|
|
309
337
|
if (await testCaddy())
|
|
310
338
|
return caddyPath;
|
|
311
339
|
return new Promise((resolve, reject) => {
|
|
340
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
341
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
342
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
343
|
+
}
|
|
312
344
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
313
|
-
let _platform = (0,
|
|
345
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
314
346
|
_platform === "win32" && (_platform = "windows");
|
|
315
347
|
let _arch = import_node_process4.default.arch.toString();
|
|
316
348
|
_arch === "x64" && (_arch = "amd64");
|
|
@@ -323,6 +355,9 @@ async function download() {
|
|
|
323
355
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
324
356
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
325
357
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
358
|
+
const chmodCaddyOnce = once(() => {
|
|
359
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
360
|
+
});
|
|
326
361
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
327
362
|
agent: {
|
|
328
363
|
http: httpAgent,
|
|
@@ -330,11 +365,12 @@ async function download() {
|
|
|
330
365
|
}
|
|
331
366
|
}).on("downloadProgress", (progress) => {
|
|
332
367
|
logProgress(progress.percent);
|
|
368
|
+
chmodCaddyOnce();
|
|
333
369
|
}).pipe(file).on("finish", () => {
|
|
334
370
|
logProgressOver();
|
|
335
371
|
if (import_node_process4.default.platform === "win32")
|
|
336
372
|
return resolve(caddyPath);
|
|
337
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
373
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
338
374
|
resolve(caddyPath);
|
|
339
375
|
}).on("error", (err) => {
|
|
340
376
|
reject(err);
|
|
@@ -345,7 +381,7 @@ function testCaddy() {
|
|
|
345
381
|
return new Promise((resolve, reject) => {
|
|
346
382
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
347
383
|
return resolve(false);
|
|
348
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
384
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
349
385
|
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process3.spawn)(caddyPath, []) : (0, import_node_child_process3.spawn)("sudo", ["-E", caddyPath]);
|
|
350
386
|
child.on("close", () => {
|
|
351
387
|
return resolve(false);
|
|
@@ -417,6 +453,19 @@ var CaddyInstant = class {
|
|
|
417
453
|
});
|
|
418
454
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
419
455
|
import_node_process4.default.exit = async (code) => {
|
|
456
|
+
const port = Number(source.split(":")[1]);
|
|
457
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
458
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
459
|
+
const pwd = import_node_process4.default.cwd();
|
|
460
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
461
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
462
|
+
chmodRecursive(viteCacheDir, 511);
|
|
463
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
464
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
465
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
466
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
467
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
468
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
420
469
|
if (!restore || this.stoped)
|
|
421
470
|
return originalExit(code);
|
|
422
471
|
try {
|
|
@@ -455,31 +504,21 @@ var CaddyInstant = class {
|
|
|
455
504
|
// src/index.ts
|
|
456
505
|
var config;
|
|
457
506
|
var caddy;
|
|
458
|
-
|
|
507
|
+
var cwd = import_node_process5.default.cwd();
|
|
508
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
459
509
|
_printUrls == null ? void 0 : _printUrls();
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
(
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
base
|
|
473
|
-
}, options)).then(() => {
|
|
474
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
475
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
476
|
-
}).catch((e) => {
|
|
477
|
-
throw e;
|
|
478
|
-
});
|
|
479
|
-
} catch (e) {
|
|
480
|
-
consola.error(e);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
510
|
+
if (caddy)
|
|
511
|
+
return;
|
|
512
|
+
caddy = new CaddyInstant();
|
|
513
|
+
caddy.run(source, target, __spreadValues({
|
|
514
|
+
base
|
|
515
|
+
}, options)).then(() => {
|
|
516
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
517
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
518
|
+
}).catch((e) => {
|
|
519
|
+
throw e;
|
|
520
|
+
});
|
|
521
|
+
});
|
|
483
522
|
var unpluginFactory = (options) => ({
|
|
484
523
|
name: "unplugin-https-reverse-proxy",
|
|
485
524
|
enforce: "pre",
|
|
@@ -489,11 +528,7 @@ var unpluginFactory = (options) => ({
|
|
|
489
528
|
},
|
|
490
529
|
configureServer(server) {
|
|
491
530
|
var _a;
|
|
492
|
-
if (
|
|
493
|
-
consola.warn("please run as administrator");
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
if (config.command === "build")
|
|
531
|
+
if (config.command !== "serve")
|
|
497
532
|
return;
|
|
498
533
|
const {
|
|
499
534
|
enable = true,
|
|
@@ -501,6 +536,10 @@ var unpluginFactory = (options) => ({
|
|
|
501
536
|
} = options;
|
|
502
537
|
if (!enable)
|
|
503
538
|
return;
|
|
539
|
+
if (!isAdmin()) {
|
|
540
|
+
consola.warn("please run as administrator");
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
504
543
|
if (!target) {
|
|
505
544
|
consola.fail("please provide target");
|
|
506
545
|
return;
|
|
@@ -513,15 +552,56 @@ var unpluginFactory = (options) => ({
|
|
|
513
552
|
source = u.host;
|
|
514
553
|
}
|
|
515
554
|
const base = server.config.base || "/";
|
|
516
|
-
server.printUrls = () => vitePrintUrls(
|
|
555
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
517
556
|
}
|
|
518
557
|
},
|
|
519
558
|
webpack(compiler) {
|
|
520
|
-
var _a;
|
|
559
|
+
var _a, _b;
|
|
560
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
561
|
+
return;
|
|
562
|
+
const {
|
|
563
|
+
enable = true,
|
|
564
|
+
target = ""
|
|
565
|
+
} = options;
|
|
566
|
+
if (!enable)
|
|
567
|
+
return;
|
|
521
568
|
if (!isAdmin()) {
|
|
522
569
|
consola.warn("please run as administrator");
|
|
523
570
|
return;
|
|
524
571
|
}
|
|
572
|
+
if (!target) {
|
|
573
|
+
consola.fail("please provide target");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
const devServer = __spreadValues(__spreadValues({
|
|
577
|
+
host: "localhost",
|
|
578
|
+
port: 8080
|
|
579
|
+
}, compiler.options.devServer), (_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
|
|
580
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
581
|
+
if (caddy)
|
|
582
|
+
return;
|
|
583
|
+
const _close = (_b = compiler.close) == null ? void 0 : _b.bind(compiler);
|
|
584
|
+
if (_close) {
|
|
585
|
+
compiler.close = async (callback) => {
|
|
586
|
+
import_node_process5.default.on("exit", () => {
|
|
587
|
+
_close && _close(callback);
|
|
588
|
+
});
|
|
589
|
+
};
|
|
590
|
+
} else {
|
|
591
|
+
options.https = false;
|
|
592
|
+
}
|
|
593
|
+
caddy = new CaddyInstant();
|
|
594
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
595
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
596
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
597
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
598
|
+
});
|
|
599
|
+
}).catch((e) => {
|
|
600
|
+
throw e;
|
|
601
|
+
});
|
|
602
|
+
},
|
|
603
|
+
async rspack(compiler) {
|
|
604
|
+
var _a, _b, _c;
|
|
525
605
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
526
606
|
return;
|
|
527
607
|
const {
|
|
@@ -530,40 +610,30 @@ var unpluginFactory = (options) => ({
|
|
|
530
610
|
} = options;
|
|
531
611
|
if (!enable)
|
|
532
612
|
return;
|
|
613
|
+
if (!isAdmin()) {
|
|
614
|
+
consola.warn("please run as administrator");
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
533
617
|
if (!target) {
|
|
534
618
|
consola.fail("please provide target");
|
|
535
619
|
return;
|
|
536
620
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
options.https = false;
|
|
554
|
-
}
|
|
555
|
-
caddy = new CaddyInstant();
|
|
556
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
557
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
558
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
559
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
560
|
-
});
|
|
561
|
-
}).catch((e) => {
|
|
562
|
-
throw e;
|
|
563
|
-
});
|
|
564
|
-
} catch (e) {
|
|
565
|
-
consola.error(e);
|
|
566
|
-
}
|
|
621
|
+
const devServer = __spreadValues(__spreadValues({
|
|
622
|
+
host: "localhost",
|
|
623
|
+
port: 8080
|
|
624
|
+
}, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
625
|
+
cwd
|
|
626
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
|
|
627
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
628
|
+
if (caddy)
|
|
629
|
+
return;
|
|
630
|
+
caddy = new CaddyInstant();
|
|
631
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
632
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
633
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
634
|
+
}).catch((e) => {
|
|
635
|
+
throw e;
|
|
636
|
+
});
|
|
567
637
|
}
|
|
568
638
|
});
|
|
569
639
|
var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as _unplugin from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
import { ViteDevServer } from 'vite';
|
|
4
3
|
import { Options } from './types.cjs';
|
|
5
4
|
|
|
6
|
-
declare
|
|
5
|
+
declare const vitePrintUrls: (options: Options, source: string, target: string, base?: string | undefined, _printUrls?: (() => void) | undefined) => void;
|
|
7
6
|
declare const unpluginFactory: UnpluginFactory<Options>;
|
|
8
7
|
declare const unplugin: _unplugin.UnpluginInstance<Options, boolean>;
|
|
9
8
|
|