unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.20
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 +105 -2
- package/dist/chunk-2VGRJ3QS.js +45 -0
- package/dist/chunk-I6DP2OII.js +695 -0
- package/dist/esbuild.cjs +334 -160
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +334 -160
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +270 -234
- package/dist/nuxt.js +24 -22
- package/dist/rollup.cjs +334 -160
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +760 -0
- package/dist/rspack.d.cts +5 -0
- package/dist/rspack.d.ts +5 -0
- package/dist/rspack.js +10 -0
- package/dist/types.cjs +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.js +1 -1
- package/dist/vite.cjs +334 -160
- package/dist/vite.d.cts +1 -2
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +7 -4
- package/dist/webpack.cjs +334 -160
- package/dist/webpack.js +7 -4
- package/package.json +48 -28
- package/scripts/postinstall.cjs +308 -0
- package/src/caddy/constants.ts +14 -1
- package/src/caddy/index.ts +230 -76
- package/src/caddy/utils.ts +18 -0
- package/src/host/index.ts +9 -15
- package/src/index.ts +110 -83
- package/src/nuxt.ts +26 -19
- package/src/rspack.ts +5 -0
- package/dist/chunk-DDD5N75Y.js +0 -11
- package/dist/chunk-N6ZBBGYD.js +0 -516
- package/dist/chunk-RUJE3YFB.js +0 -63
- package/dist/chunk-VGLXVBHU.js +0 -11
- package/scripts/postinstall.ts +0 -19
package/dist/vite.cjs
CHANGED
|
@@ -3,22 +3,8 @@ var __create = Object.create;
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
8
|
var __export = (target, all) => {
|
|
23
9
|
for (var name in all)
|
|
24
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -51,7 +37,6 @@ var import_unplugin2 = require("unplugin");
|
|
|
51
37
|
|
|
52
38
|
// src/index.ts
|
|
53
39
|
var import_node_process5 = __toESM(require("process"), 1);
|
|
54
|
-
var import_node_fs3 = require("fs");
|
|
55
40
|
var import_unplugin = require("unplugin");
|
|
56
41
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
57
42
|
|
|
@@ -72,12 +57,21 @@ async function chmodRecursive(_path, mode) {
|
|
|
72
57
|
await chmodRecursive(import_node_path.default.join(_path, child), mode);
|
|
73
58
|
}
|
|
74
59
|
}
|
|
60
|
+
function once(fn) {
|
|
61
|
+
let called = false;
|
|
62
|
+
return (...args) => {
|
|
63
|
+
if (called)
|
|
64
|
+
return;
|
|
65
|
+
called = true;
|
|
66
|
+
return fn(...args);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
75
69
|
function isAdmin() {
|
|
76
70
|
if (import_node_process.default.platform === "win32") {
|
|
77
71
|
try {
|
|
78
72
|
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
79
73
|
return true;
|
|
80
|
-
} catch
|
|
74
|
+
} catch {
|
|
81
75
|
return false;
|
|
82
76
|
}
|
|
83
77
|
} else {
|
|
@@ -86,25 +80,24 @@ function isAdmin() {
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
// src/caddy/index.ts
|
|
89
|
-
var
|
|
83
|
+
var import_node_os2 = require("os");
|
|
90
84
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
91
85
|
var import_node_fs2 = require("fs");
|
|
92
|
-
var
|
|
86
|
+
var import_node_child_process4 = require("child_process");
|
|
87
|
+
var import_promises2 = require("fs/promises");
|
|
93
88
|
var import_got_cjs = require("got-cjs");
|
|
94
89
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
95
90
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
96
|
-
var
|
|
91
|
+
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
97
92
|
|
|
98
93
|
// src/host/index.ts
|
|
99
94
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
100
95
|
var import_node_child_process2 = require("child_process");
|
|
101
96
|
var import_node_fs = require("fs");
|
|
102
|
-
var
|
|
103
|
-
var
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
107
|
-
});
|
|
97
|
+
var import_node_util = require("util");
|
|
98
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
99
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
100
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
108
101
|
function getPathOfSystemHostsPath() {
|
|
109
102
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
110
103
|
}
|
|
@@ -125,29 +118,38 @@ async function syncHost() {
|
|
|
125
118
|
async function addHost(ip, host) {
|
|
126
119
|
if (import_node_process2.default.platform !== "win32")
|
|
127
120
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
await _setHost("127.0.0.1", "localhost");
|
|
122
|
+
await _setHost(ip, host);
|
|
130
123
|
if (ip === "localhost")
|
|
131
|
-
|
|
132
|
-
await hostInstance.updateFinish();
|
|
124
|
+
await _setHost("127.0.0.1", host);
|
|
133
125
|
return await syncHost();
|
|
134
126
|
}
|
|
135
127
|
async function removeHost(ip, host) {
|
|
136
128
|
if (import_node_process2.default.platform !== "win32")
|
|
137
129
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
138
|
-
|
|
130
|
+
await _removeHost(ip, host);
|
|
139
131
|
if (ip === "localhost")
|
|
140
|
-
|
|
141
|
-
await hostInstance.updateFinish();
|
|
132
|
+
await _removeHost("127.0.0.1", host);
|
|
142
133
|
return await syncHost();
|
|
143
134
|
}
|
|
144
135
|
|
|
145
136
|
// src/caddy/constants.ts
|
|
146
137
|
var import_node_path2 = require("path");
|
|
138
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
147
139
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
148
|
-
var
|
|
140
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
141
|
+
import_dotenv_flow.default.config({
|
|
142
|
+
silent: true
|
|
143
|
+
});
|
|
144
|
+
function resolvePath(path2) {
|
|
145
|
+
if (path2.startsWith("~"))
|
|
146
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
147
|
+
return path2;
|
|
148
|
+
}
|
|
149
|
+
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");
|
|
149
150
|
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
150
151
|
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
152
|
+
var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
|
|
151
153
|
var supportList = [
|
|
152
154
|
{
|
|
153
155
|
platform: "dragonfly",
|
|
@@ -261,6 +263,7 @@ var supportList = [
|
|
|
261
263
|
|
|
262
264
|
// src/caddy/utils.ts
|
|
263
265
|
var import_node_net = require("net");
|
|
266
|
+
var import_node_child_process3 = require("child_process");
|
|
264
267
|
var import_ora = __toESM(require("ora"), 1);
|
|
265
268
|
var spinner;
|
|
266
269
|
function tryPort(port) {
|
|
@@ -281,6 +284,18 @@ function tryPort(port) {
|
|
|
281
284
|
}
|
|
282
285
|
});
|
|
283
286
|
}
|
|
287
|
+
async function kill(port) {
|
|
288
|
+
return new Promise((resolve, reject) => {
|
|
289
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
290
|
+
if (err) {
|
|
291
|
+
reject(err);
|
|
292
|
+
} else {
|
|
293
|
+
consola.log(stdout);
|
|
294
|
+
resolve();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
284
299
|
function getNumber(number) {
|
|
285
300
|
if (number <= 0)
|
|
286
301
|
return "0%";
|
|
@@ -319,8 +334,12 @@ async function download() {
|
|
|
319
334
|
if (await testCaddy())
|
|
320
335
|
return caddyPath;
|
|
321
336
|
return new Promise((resolve, reject) => {
|
|
337
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
338
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
339
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
340
|
+
}
|
|
322
341
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
323
|
-
let _platform = (0,
|
|
342
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
324
343
|
_platform === "win32" && (_platform = "windows");
|
|
325
344
|
let _arch = import_node_process4.default.arch.toString();
|
|
326
345
|
_arch === "x64" && (_arch = "amd64");
|
|
@@ -333,6 +352,9 @@ async function download() {
|
|
|
333
352
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
334
353
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
335
354
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
355
|
+
const chmodCaddyOnce = once(() => {
|
|
356
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
357
|
+
});
|
|
336
358
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
337
359
|
agent: {
|
|
338
360
|
http: httpAgent,
|
|
@@ -340,11 +362,12 @@ async function download() {
|
|
|
340
362
|
}
|
|
341
363
|
}).on("downloadProgress", (progress) => {
|
|
342
364
|
logProgress(progress.percent);
|
|
365
|
+
chmodCaddyOnce();
|
|
343
366
|
}).pipe(file).on("finish", () => {
|
|
344
367
|
logProgressOver();
|
|
345
368
|
if (import_node_process4.default.platform === "win32")
|
|
346
369
|
return resolve(caddyPath);
|
|
347
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
370
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
348
371
|
resolve(caddyPath);
|
|
349
372
|
}).on("error", (err) => {
|
|
350
373
|
reject(err);
|
|
@@ -355,8 +378,8 @@ function testCaddy() {
|
|
|
355
378
|
return new Promise((resolve, reject) => {
|
|
356
379
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
357
380
|
return resolve(false);
|
|
358
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
359
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
381
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
382
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
360
383
|
child.on("close", () => {
|
|
361
384
|
return resolve(false);
|
|
362
385
|
});
|
|
@@ -372,9 +395,41 @@ var CaddyInstant = class {
|
|
|
372
395
|
constructor() {
|
|
373
396
|
this.inited = false;
|
|
374
397
|
this.stoped = false;
|
|
375
|
-
|
|
398
|
+
/** has locked */
|
|
399
|
+
this.locked = false;
|
|
400
|
+
testCaddy().then(async () => {
|
|
401
|
+
await this.getCaddyfile();
|
|
376
402
|
this.inited = true;
|
|
377
403
|
});
|
|
404
|
+
this.locked = this.checkLock();
|
|
405
|
+
}
|
|
406
|
+
checkLock() {
|
|
407
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
408
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
409
|
+
return lockfile.checkSync(caddyLockFilePath);
|
|
410
|
+
}
|
|
411
|
+
async getCaddyfile() {
|
|
412
|
+
if (!(0, import_node_fs2.existsSync)(caddyFilePath))
|
|
413
|
+
await this.initCaddyfile();
|
|
414
|
+
this.caddyfile = await (0, import_promises2.readFile)(caddyFilePath, "utf-8");
|
|
415
|
+
return this.caddyfile;
|
|
416
|
+
}
|
|
417
|
+
async initCaddyfile() {
|
|
418
|
+
const contet = `
|
|
419
|
+
{
|
|
420
|
+
debug
|
|
421
|
+
auto_https disable_redirects
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
`;
|
|
425
|
+
await (0, import_promises2.writeFile)(caddyFilePath, contet);
|
|
426
|
+
this.caddyfile = contet;
|
|
427
|
+
}
|
|
428
|
+
async writeCaddyfile() {
|
|
429
|
+
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
|
430
|
+
}
|
|
431
|
+
async deleteCaddyfile() {
|
|
432
|
+
return await (0, import_promises2.unlink)(caddyFilePath);
|
|
378
433
|
}
|
|
379
434
|
async init() {
|
|
380
435
|
await download();
|
|
@@ -393,103 +448,185 @@ var CaddyInstant = class {
|
|
|
393
448
|
showCaddyLog = false,
|
|
394
449
|
https = false
|
|
395
450
|
} = options || {};
|
|
451
|
+
this._source = source;
|
|
452
|
+
this._target = target;
|
|
396
453
|
if (!this.inited)
|
|
397
454
|
await this.init();
|
|
398
|
-
if (https && await tryPort(443))
|
|
399
|
-
await (0, import_kill_port.default)(443, "tcp");
|
|
400
|
-
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
401
|
-
await (0, import_kill_port.default)(80, "tcp");
|
|
402
455
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
403
456
|
throw new Error("update host failed");
|
|
404
457
|
consola.success("update host success\n");
|
|
458
|
+
await this.getCaddyfile();
|
|
459
|
+
if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
|
|
460
|
+
this.caddyfile = `${this.caddyfile}
|
|
461
|
+
${target.split(":")[0]}${https ? "" : ":80"} {
|
|
462
|
+
${https ? "tls internal" : ""}
|
|
463
|
+
reverse_proxy http://${source} {
|
|
464
|
+
health_uri /
|
|
465
|
+
health_interval 2s
|
|
466
|
+
health_timeout 5s
|
|
467
|
+
fail_duration 2s
|
|
468
|
+
unhealthy_status 502 503 504 404
|
|
469
|
+
lb_try_duration 3s
|
|
470
|
+
lb_try_interval 300ms
|
|
471
|
+
|
|
472
|
+
@error status 502 503 504 404
|
|
473
|
+
handle_response @error {
|
|
474
|
+
respond * 503 {
|
|
475
|
+
body "Service Unavailable"
|
|
476
|
+
close
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
`;
|
|
483
|
+
await this.writeCaddyfile();
|
|
484
|
+
}
|
|
485
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
486
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
487
|
+
if (!this.locked) {
|
|
488
|
+
if (await tryPort(443))
|
|
489
|
+
await kill(443);
|
|
490
|
+
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
491
|
+
await kill(80);
|
|
492
|
+
}
|
|
405
493
|
return new Promise((resolve, reject) => {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
494
|
+
var _a, _b;
|
|
495
|
+
const setupCleanup = () => {
|
|
496
|
+
import_node_process4.default.on("SIGINT", async () => {
|
|
497
|
+
if (this.stoped)
|
|
498
|
+
return;
|
|
499
|
+
import_node_process4.default.stdin.resume();
|
|
500
|
+
try {
|
|
501
|
+
await this.baseCleanup(restore);
|
|
502
|
+
} finally {
|
|
503
|
+
this.stoped = true;
|
|
504
|
+
import_node_process4.default.nextTick(() => {
|
|
505
|
+
import_node_process4.default.exit();
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
510
|
+
import_node_process4.default.exit = async (code) => {
|
|
511
|
+
const port = Number(source.split(":")[1]);
|
|
512
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
513
|
+
await kill(port);
|
|
514
|
+
const pwd = import_node_process4.default.cwd();
|
|
515
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
516
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
517
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
518
|
+
});
|
|
519
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
520
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
521
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
522
|
+
});
|
|
523
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
524
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
525
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
526
|
+
});
|
|
527
|
+
if (this.stoped)
|
|
528
|
+
return originalExit(code);
|
|
529
|
+
import_node_process4.default.stdin.resume();
|
|
530
|
+
try {
|
|
531
|
+
await this.baseCleanup();
|
|
532
|
+
} finally {
|
|
533
|
+
this.stoped = true;
|
|
534
|
+
import_node_process4.default.nextTick(() => {
|
|
535
|
+
originalExit(code);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
};
|
|
446
539
|
};
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
540
|
+
if (!this.locked) {
|
|
541
|
+
this._caddyChild = import_node_process4.default.platform !== "win32" ? (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : (0, import_node_child_process4.spawn)(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
|
|
542
|
+
lockfile.lockSync(caddyLockFilePath);
|
|
543
|
+
this._caddyChild.on("error", (err) => {
|
|
544
|
+
return reject(err);
|
|
545
|
+
});
|
|
546
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", async (data) => {
|
|
547
|
+
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
548
|
+
for (const line of lines) {
|
|
549
|
+
showCaddyLog && line && console.info(line);
|
|
550
|
+
if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
|
|
551
|
+
if (line.includes("parsing caddyfile tokens")) {
|
|
552
|
+
consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
|
|
553
|
+
|
|
554
|
+
${line}
|
|
555
|
+
`);
|
|
556
|
+
await this.baseCleanup();
|
|
557
|
+
import_node_process4.default.exit();
|
|
558
|
+
} else {
|
|
559
|
+
consola.error(`${line}
|
|
560
|
+
`);
|
|
561
|
+
return reject(line);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
if (line.includes("config file changed"))
|
|
565
|
+
consola.success("Detect added a new reverse proxy config, restarted.\n");
|
|
566
|
+
if (line.includes("caddy proxying") || line.includes("serving initial"))
|
|
567
|
+
return resolve();
|
|
454
568
|
}
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
569
|
+
});
|
|
570
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
571
|
+
consola.info(_data.toString());
|
|
572
|
+
resolve();
|
|
573
|
+
});
|
|
574
|
+
setupCleanup();
|
|
575
|
+
} else {
|
|
576
|
+
consola.info("Caddy is running in another process.");
|
|
577
|
+
setupCleanup();
|
|
578
|
+
return resolve();
|
|
579
|
+
}
|
|
461
580
|
});
|
|
462
581
|
}
|
|
582
|
+
async baseCleanup(restore = true) {
|
|
583
|
+
var _a;
|
|
584
|
+
try {
|
|
585
|
+
if (restore && this._source && this._target) {
|
|
586
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
587
|
+
consola.success("Restore host success.\n");
|
|
588
|
+
else
|
|
589
|
+
consola.fail("Restore host failed.\n");
|
|
590
|
+
}
|
|
591
|
+
} catch (e) {
|
|
592
|
+
consola.error(e);
|
|
593
|
+
consola.fail("Restore host failed.\n");
|
|
594
|
+
}
|
|
595
|
+
if (!this.locked && !this.stoped) {
|
|
596
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
597
|
+
try {
|
|
598
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
599
|
+
});
|
|
600
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
601
|
+
});
|
|
602
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
603
|
+
});
|
|
604
|
+
} catch (e) {
|
|
605
|
+
consola.error(e);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
463
609
|
};
|
|
464
610
|
|
|
465
611
|
// src/index.ts
|
|
466
612
|
var config;
|
|
467
613
|
var caddy;
|
|
468
|
-
var
|
|
469
|
-
|
|
614
|
+
var cwd = import_node_process5.default.cwd();
|
|
615
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
470
616
|
_printUrls == null ? void 0 : _printUrls();
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
485
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
486
|
-
}).catch((e) => {
|
|
487
|
-
throw e;
|
|
488
|
-
});
|
|
489
|
-
} catch (e) {
|
|
490
|
-
consola.error(e);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
617
|
+
if (caddy)
|
|
618
|
+
return;
|
|
619
|
+
caddy = new CaddyInstant();
|
|
620
|
+
caddy.run(source, target, {
|
|
621
|
+
base,
|
|
622
|
+
...options
|
|
623
|
+
}).then(() => {
|
|
624
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
625
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
626
|
+
}).catch((e) => {
|
|
627
|
+
throw e;
|
|
628
|
+
});
|
|
629
|
+
});
|
|
493
630
|
var unpluginFactory = (options) => ({
|
|
494
631
|
name: "unplugin-https-reverse-proxy",
|
|
495
632
|
enforce: "pre",
|
|
@@ -499,11 +636,7 @@ var unpluginFactory = (options) => ({
|
|
|
499
636
|
},
|
|
500
637
|
configureServer(server) {
|
|
501
638
|
var _a;
|
|
502
|
-
if (
|
|
503
|
-
consola.warn("please run as administrator");
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
if (config.command === "build")
|
|
639
|
+
if (config.command !== "serve")
|
|
507
640
|
return;
|
|
508
641
|
const {
|
|
509
642
|
enable = true,
|
|
@@ -511,6 +644,10 @@ var unpluginFactory = (options) => ({
|
|
|
511
644
|
} = options;
|
|
512
645
|
if (!enable)
|
|
513
646
|
return;
|
|
647
|
+
if (!isAdmin()) {
|
|
648
|
+
consola.warn("please run as administrator");
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
514
651
|
if (!target) {
|
|
515
652
|
consola.fail("please provide target");
|
|
516
653
|
return;
|
|
@@ -523,15 +660,61 @@ var unpluginFactory = (options) => ({
|
|
|
523
660
|
source = u.host;
|
|
524
661
|
}
|
|
525
662
|
const base = server.config.base || "/";
|
|
526
|
-
server.printUrls = () => vitePrintUrls(
|
|
663
|
+
server.printUrls = () => vitePrintUrls(options, source, target, base, _printUrls);
|
|
527
664
|
}
|
|
528
665
|
},
|
|
529
666
|
webpack(compiler) {
|
|
530
|
-
var _a;
|
|
667
|
+
var _a, _b;
|
|
668
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
669
|
+
return;
|
|
670
|
+
const {
|
|
671
|
+
enable = true,
|
|
672
|
+
target = ""
|
|
673
|
+
} = options;
|
|
674
|
+
if (!enable)
|
|
675
|
+
return;
|
|
531
676
|
if (!isAdmin()) {
|
|
532
677
|
consola.warn("please run as administrator");
|
|
533
678
|
return;
|
|
534
679
|
}
|
|
680
|
+
if (!target) {
|
|
681
|
+
consola.fail("please provide target");
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
684
|
+
const devServer = {
|
|
685
|
+
host: "localhost",
|
|
686
|
+
port: 8080,
|
|
687
|
+
...compiler.options.devServer,
|
|
688
|
+
// @ts-expect-error vuecli
|
|
689
|
+
...(_a = import_node_process5.default.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer
|
|
690
|
+
};
|
|
691
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
692
|
+
if (caddy)
|
|
693
|
+
return;
|
|
694
|
+
const _close = (_b = compiler.close) == null ? void 0 : _b.bind(compiler);
|
|
695
|
+
if (_close) {
|
|
696
|
+
compiler.close = async (callback) => {
|
|
697
|
+
import_node_process5.default.on("exit", () => {
|
|
698
|
+
_close && _close(callback);
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
} else {
|
|
702
|
+
options.https = false;
|
|
703
|
+
}
|
|
704
|
+
caddy = new CaddyInstant();
|
|
705
|
+
caddy.run(source, target, {
|
|
706
|
+
...options
|
|
707
|
+
}).then(() => {
|
|
708
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
709
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
710
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
711
|
+
});
|
|
712
|
+
}).catch((e) => {
|
|
713
|
+
throw e;
|
|
714
|
+
});
|
|
715
|
+
},
|
|
716
|
+
async rspack(compiler) {
|
|
717
|
+
var _a, _b, _c;
|
|
535
718
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
536
719
|
return;
|
|
537
720
|
const {
|
|
@@ -540,46 +723,37 @@ var unpluginFactory = (options) => ({
|
|
|
540
723
|
} = options;
|
|
541
724
|
if (!enable)
|
|
542
725
|
return;
|
|
726
|
+
if (!isAdmin()) {
|
|
727
|
+
consola.warn("please run as administrator");
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
543
730
|
if (!target) {
|
|
544
731
|
consola.fail("please provide target");
|
|
545
732
|
return;
|
|
546
733
|
}
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
caddy = new CaddyInstant();
|
|
569
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
570
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
571
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
572
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
573
|
-
});
|
|
574
|
-
}).catch((e) => {
|
|
575
|
-
throw e;
|
|
576
|
-
});
|
|
577
|
-
} catch (e) {
|
|
578
|
-
consola.error(e);
|
|
579
|
-
}
|
|
734
|
+
const devServer = {
|
|
735
|
+
host: "localhost",
|
|
736
|
+
port: 8080,
|
|
737
|
+
...compiler.options.devServer,
|
|
738
|
+
...(_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
|
|
739
|
+
cwd
|
|
740
|
+
}))) == null ? void 0 : _b.content) == null ? void 0 : _c.server
|
|
741
|
+
};
|
|
742
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
743
|
+
if (caddy)
|
|
744
|
+
return;
|
|
745
|
+
caddy = new CaddyInstant();
|
|
746
|
+
caddy.run(source, target, {
|
|
747
|
+
...options
|
|
748
|
+
}).then(() => {
|
|
749
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
750
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
751
|
+
}).catch((e) => {
|
|
752
|
+
throw e;
|
|
753
|
+
});
|
|
580
754
|
}
|
|
581
755
|
});
|
|
582
756
|
|
|
583
757
|
// src/vite.ts
|
|
584
758
|
var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
|
|
585
|
-
exports.default = module.exports;
|
|
759
|
+
module.exports = module.exports;exports.default = module.exports;
|