unplugin-https-reverse-proxy 1.0.0-beta.2 → 1.0.0-beta.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/README.md +105 -2
- package/dist/chunk-2VGRJ3QS.js +45 -0
- package/dist/chunk-KVE7AVSI.js +700 -0
- package/dist/esbuild.cjs +339 -160
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +339 -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 +275 -234
- package/dist/nuxt.js +24 -22
- package/dist/rollup.cjs +339 -160
- package/dist/rollup.js +2 -2
- package/dist/rspack.cjs +765 -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 +339 -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 +339 -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 +234 -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/nuxt.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 });
|
|
@@ -47,16 +33,9 @@ __export(nuxt_exports, {
|
|
|
47
33
|
default: () => nuxt_default
|
|
48
34
|
});
|
|
49
35
|
module.exports = __toCommonJS(nuxt_exports);
|
|
36
|
+
var import_node_process6 = __toESM(require("process"), 1);
|
|
50
37
|
var import_kit = require("@nuxt/kit");
|
|
51
|
-
|
|
52
|
-
// src/vite.ts
|
|
53
|
-
var import_unplugin2 = require("unplugin");
|
|
54
|
-
|
|
55
|
-
// src/index.ts
|
|
56
|
-
var import_node_process5 = __toESM(require("process"), 1);
|
|
57
|
-
var import_node_fs3 = require("fs");
|
|
58
|
-
var import_unplugin = require("unplugin");
|
|
59
|
-
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
38
|
+
var import_schema = require("@nuxt/schema");
|
|
60
39
|
|
|
61
40
|
// src/utils.ts
|
|
62
41
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -89,7 +68,7 @@ function isAdmin() {
|
|
|
89
68
|
try {
|
|
90
69
|
(0, import_node_child_process.execSync)("net session", { stdio: "ignore" });
|
|
91
70
|
return true;
|
|
92
|
-
} catch
|
|
71
|
+
} catch {
|
|
93
72
|
return false;
|
|
94
73
|
}
|
|
95
74
|
} else {
|
|
@@ -97,26 +76,30 @@ function isAdmin() {
|
|
|
97
76
|
}
|
|
98
77
|
}
|
|
99
78
|
|
|
79
|
+
// src/index.ts
|
|
80
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
81
|
+
var import_unplugin = require("unplugin");
|
|
82
|
+
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
83
|
+
|
|
100
84
|
// src/caddy/index.ts
|
|
101
|
-
var
|
|
85
|
+
var import_node_os2 = require("os");
|
|
102
86
|
var import_node_process4 = __toESM(require("process"), 1);
|
|
103
87
|
var import_node_fs2 = require("fs");
|
|
104
|
-
var
|
|
88
|
+
var import_node_child_process4 = require("child_process");
|
|
89
|
+
var import_promises2 = require("fs/promises");
|
|
105
90
|
var import_got_cjs = require("got-cjs");
|
|
106
91
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
107
92
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
108
|
-
var
|
|
93
|
+
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
109
94
|
|
|
110
95
|
// src/host/index.ts
|
|
111
96
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
112
97
|
var import_node_child_process2 = require("child_process");
|
|
113
98
|
var import_node_fs = require("fs");
|
|
114
|
-
var
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
hostsFile: getPathOfSystemHostsPath()
|
|
119
|
-
});
|
|
99
|
+
var import_node_util = require("util");
|
|
100
|
+
var import_hostile = __toESM(require("hostile"), 1);
|
|
101
|
+
var _setHost = (0, import_node_util.promisify)(import_hostile.default.set);
|
|
102
|
+
var _removeHost = (0, import_node_util.promisify)(import_hostile.default.remove);
|
|
120
103
|
function getPathOfSystemHostsPath() {
|
|
121
104
|
return import_node_process2.default.platform === "win32" ? `${import_node_process2.default.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
|
|
122
105
|
}
|
|
@@ -137,29 +120,38 @@ async function syncHost() {
|
|
|
137
120
|
async function addHost(ip, host) {
|
|
138
121
|
if (import_node_process2.default.platform !== "win32")
|
|
139
122
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
await _setHost("127.0.0.1", "localhost");
|
|
124
|
+
await _setHost(ip, host);
|
|
142
125
|
if (ip === "localhost")
|
|
143
|
-
|
|
144
|
-
await hostInstance.updateFinish();
|
|
126
|
+
await _setHost("127.0.0.1", host);
|
|
145
127
|
return await syncHost();
|
|
146
128
|
}
|
|
147
129
|
async function removeHost(ip, host) {
|
|
148
130
|
if (import_node_process2.default.platform !== "win32")
|
|
149
131
|
(0, import_node_fs.chmodSync)(getPathOfSystemHostsPath(), 511);
|
|
150
|
-
|
|
132
|
+
await _removeHost(ip, host);
|
|
151
133
|
if (ip === "localhost")
|
|
152
|
-
|
|
153
|
-
await hostInstance.updateFinish();
|
|
134
|
+
await _removeHost("127.0.0.1", host);
|
|
154
135
|
return await syncHost();
|
|
155
136
|
}
|
|
156
137
|
|
|
157
138
|
// src/caddy/constants.ts
|
|
158
139
|
var import_node_path2 = require("path");
|
|
140
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
159
141
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
160
|
-
var
|
|
142
|
+
var import_dotenv_flow = __toESM(require("dotenv-flow"), 1);
|
|
143
|
+
import_dotenv_flow.default.config({
|
|
144
|
+
silent: true
|
|
145
|
+
});
|
|
146
|
+
function resolvePath(path2) {
|
|
147
|
+
if (path2.startsWith("~"))
|
|
148
|
+
return (0, import_node_path2.join)(import_node_os.default.homedir() || "", path2.slice(1));
|
|
149
|
+
return path2;
|
|
150
|
+
}
|
|
151
|
+
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");
|
|
161
152
|
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
162
153
|
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
154
|
+
var caddyLockFilePath = (0, import_node_path2.join)(TEMP_DIR, "caddylock");
|
|
163
155
|
var supportList = [
|
|
164
156
|
{
|
|
165
157
|
platform: "dragonfly",
|
|
@@ -273,6 +265,7 @@ var supportList = [
|
|
|
273
265
|
|
|
274
266
|
// src/caddy/utils.ts
|
|
275
267
|
var import_node_net = require("net");
|
|
268
|
+
var import_node_child_process3 = require("child_process");
|
|
276
269
|
var import_ora = __toESM(require("ora"), 1);
|
|
277
270
|
var spinner;
|
|
278
271
|
function tryPort(port) {
|
|
@@ -293,6 +286,18 @@ function tryPort(port) {
|
|
|
293
286
|
}
|
|
294
287
|
});
|
|
295
288
|
}
|
|
289
|
+
async function kill(port) {
|
|
290
|
+
return new Promise((resolve, reject) => {
|
|
291
|
+
(0, import_node_child_process3.exec)(`npx @maxbo/free-port ${port} -s`, (err, stdout, stderr) => {
|
|
292
|
+
if (err) {
|
|
293
|
+
reject(err);
|
|
294
|
+
} else {
|
|
295
|
+
consola.log(stdout);
|
|
296
|
+
resolve();
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
|
296
301
|
function getNumber(number) {
|
|
297
302
|
if (number <= 0)
|
|
298
303
|
return "0%";
|
|
@@ -331,8 +336,12 @@ async function download() {
|
|
|
331
336
|
if (await testCaddy())
|
|
332
337
|
return caddyPath;
|
|
333
338
|
return new Promise((resolve, reject) => {
|
|
339
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
340
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
341
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
342
|
+
}
|
|
334
343
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
335
|
-
let _platform = (0,
|
|
344
|
+
let _platform = (0, import_node_os2.platform)().toString();
|
|
336
345
|
_platform === "win32" && (_platform = "windows");
|
|
337
346
|
let _arch = import_node_process4.default.arch.toString();
|
|
338
347
|
_arch === "x64" && (_arch = "amd64");
|
|
@@ -345,6 +354,9 @@ async function download() {
|
|
|
345
354
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
346
355
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
347
356
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
357
|
+
const chmodCaddyOnce = once(() => {
|
|
358
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
359
|
+
});
|
|
348
360
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
349
361
|
agent: {
|
|
350
362
|
http: httpAgent,
|
|
@@ -352,11 +364,12 @@ async function download() {
|
|
|
352
364
|
}
|
|
353
365
|
}).on("downloadProgress", (progress) => {
|
|
354
366
|
logProgress(progress.percent);
|
|
367
|
+
chmodCaddyOnce();
|
|
355
368
|
}).pipe(file).on("finish", () => {
|
|
356
369
|
logProgressOver();
|
|
357
370
|
if (import_node_process4.default.platform === "win32")
|
|
358
371
|
return resolve(caddyPath);
|
|
359
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
372
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
360
373
|
resolve(caddyPath);
|
|
361
374
|
}).on("error", (err) => {
|
|
362
375
|
reject(err);
|
|
@@ -367,8 +380,8 @@ function testCaddy() {
|
|
|
367
380
|
return new Promise((resolve, reject) => {
|
|
368
381
|
if (!(0, import_node_fs2.existsSync)(caddyPath))
|
|
369
382
|
return resolve(false);
|
|
370
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
371
|
-
const child = import_node_process4.default.platform === "win32" ? (0,
|
|
383
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
384
|
+
const child = import_node_process4.default.platform === "win32" ? (0, import_node_child_process4.spawn)(caddyPath, []) : (0, import_node_child_process4.spawn)("sudo", ["-E", caddyPath]);
|
|
372
385
|
child.on("close", () => {
|
|
373
386
|
return resolve(false);
|
|
374
387
|
});
|
|
@@ -384,9 +397,41 @@ var CaddyInstant = class {
|
|
|
384
397
|
constructor() {
|
|
385
398
|
this.inited = false;
|
|
386
399
|
this.stoped = false;
|
|
387
|
-
|
|
400
|
+
/** has locked */
|
|
401
|
+
this.locked = false;
|
|
402
|
+
testCaddy().then(async () => {
|
|
403
|
+
await this.getCaddyfile();
|
|
388
404
|
this.inited = true;
|
|
389
405
|
});
|
|
406
|
+
this.locked = this.checkLock();
|
|
407
|
+
}
|
|
408
|
+
checkLock() {
|
|
409
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
410
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
411
|
+
return lockfile.checkSync(caddyLockFilePath);
|
|
412
|
+
}
|
|
413
|
+
async getCaddyfile() {
|
|
414
|
+
if (!(0, import_node_fs2.existsSync)(caddyFilePath))
|
|
415
|
+
await this.initCaddyfile();
|
|
416
|
+
this.caddyfile = await (0, import_promises2.readFile)(caddyFilePath, "utf-8");
|
|
417
|
+
return this.caddyfile;
|
|
418
|
+
}
|
|
419
|
+
async initCaddyfile() {
|
|
420
|
+
const contet = `
|
|
421
|
+
{
|
|
422
|
+
debug
|
|
423
|
+
auto_https disable_redirects
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
`;
|
|
427
|
+
await (0, import_promises2.writeFile)(caddyFilePath, contet);
|
|
428
|
+
this.caddyfile = contet;
|
|
429
|
+
}
|
|
430
|
+
async writeCaddyfile() {
|
|
431
|
+
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
|
432
|
+
}
|
|
433
|
+
async deleteCaddyfile() {
|
|
434
|
+
return await (0, import_promises2.unlink)(caddyFilePath);
|
|
390
435
|
}
|
|
391
436
|
async init() {
|
|
392
437
|
await download();
|
|
@@ -405,146 +450,198 @@ var CaddyInstant = class {
|
|
|
405
450
|
showCaddyLog = false,
|
|
406
451
|
https = false
|
|
407
452
|
} = options || {};
|
|
453
|
+
this._source = source;
|
|
454
|
+
this._target = target;
|
|
408
455
|
if (!this.inited)
|
|
409
456
|
await this.init();
|
|
410
|
-
if (https && await tryPort(443))
|
|
411
|
-
await (0, import_kill_port.default)(443, "tcp");
|
|
412
|
-
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
413
|
-
await (0, import_kill_port.default)(80, "tcp");
|
|
414
457
|
if (!await addHost(source.split(":")[0], target.split(":")[0]))
|
|
415
458
|
throw new Error("update host failed");
|
|
416
459
|
consola.success("update host success\n");
|
|
460
|
+
await this.getCaddyfile();
|
|
461
|
+
if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
|
|
462
|
+
this.caddyfile = `${this.caddyfile}
|
|
463
|
+
${target.split(":")[0]}${https ? "" : ":80"} {
|
|
464
|
+
${https ? "tls internal" : ""}
|
|
465
|
+
reverse_proxy http://${source} {
|
|
466
|
+
health_uri ${base}
|
|
467
|
+
health_interval 2s
|
|
468
|
+
health_timeout 5s
|
|
469
|
+
fail_duration 2s
|
|
470
|
+
unhealthy_status 502 503 504 404
|
|
471
|
+
lb_try_duration 3s
|
|
472
|
+
lb_try_interval 300ms
|
|
473
|
+
health_headers {
|
|
474
|
+
Accept text/html
|
|
475
|
+
Accept-Encoding gzip, deflate, br
|
|
476
|
+
User-Agent Caddy-Health-Check
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
@error status 502 503 504 404
|
|
480
|
+
handle_response @error {
|
|
481
|
+
respond * 503 {
|
|
482
|
+
body "Service Unavailable"
|
|
483
|
+
close
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
`;
|
|
490
|
+
await this.writeCaddyfile();
|
|
491
|
+
}
|
|
492
|
+
if (!(0, import_node_fs2.existsSync)(caddyLockFilePath))
|
|
493
|
+
(0, import_node_fs2.writeFileSync)(caddyLockFilePath, "");
|
|
494
|
+
if (!this.locked) {
|
|
495
|
+
if (await tryPort(443))
|
|
496
|
+
await kill(443);
|
|
497
|
+
if ((import_node_process4.default.platform === "win32" || !https) && await tryPort(80))
|
|
498
|
+
await kill(80);
|
|
499
|
+
}
|
|
417
500
|
return new Promise((resolve, reject) => {
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
501
|
+
var _a, _b;
|
|
502
|
+
const setupCleanup = () => {
|
|
503
|
+
import_node_process4.default.on("SIGINT", async () => {
|
|
504
|
+
if (this.stoped)
|
|
505
|
+
return;
|
|
506
|
+
import_node_process4.default.stdin.resume();
|
|
507
|
+
try {
|
|
508
|
+
await this.baseCleanup(restore);
|
|
509
|
+
} finally {
|
|
510
|
+
this.stoped = true;
|
|
511
|
+
import_node_process4.default.nextTick(() => {
|
|
512
|
+
import_node_process4.default.exit();
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
517
|
+
import_node_process4.default.exit = async (code) => {
|
|
518
|
+
const port = Number(source.split(":")[1]);
|
|
519
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
520
|
+
await kill(port);
|
|
521
|
+
const pwd = import_node_process4.default.cwd();
|
|
522
|
+
const viteCacheDir = `${pwd}/node_modules/.vite`;
|
|
523
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
524
|
+
await chmodRecursive(viteCacheDir, 511).catch(() => {
|
|
525
|
+
});
|
|
526
|
+
const nuxtCacheDir = `${pwd}/.nuxt`;
|
|
527
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
528
|
+
await chmodRecursive(nuxtCacheDir, 511).catch(() => {
|
|
529
|
+
});
|
|
530
|
+
const webpackCacheDir = `${pwd}/node_modules/.cache`;
|
|
531
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
532
|
+
await chmodRecursive(webpackCacheDir, 511).catch(() => {
|
|
533
|
+
});
|
|
534
|
+
if (this.stoped)
|
|
535
|
+
return originalExit(code);
|
|
536
|
+
import_node_process4.default.stdin.resume();
|
|
537
|
+
try {
|
|
538
|
+
await this.baseCleanup();
|
|
539
|
+
} finally {
|
|
540
|
+
this.stoped = true;
|
|
541
|
+
import_node_process4.default.nextTick(() => {
|
|
542
|
+
originalExit(code);
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
};
|
|
458
546
|
};
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
547
|
+
if (!this.locked) {
|
|
548
|
+
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"]);
|
|
549
|
+
lockfile.lockSync(caddyLockFilePath);
|
|
550
|
+
this._caddyChild.on("error", (err) => {
|
|
551
|
+
return reject(err);
|
|
552
|
+
});
|
|
553
|
+
(_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", async (data) => {
|
|
554
|
+
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
555
|
+
for (const line of lines) {
|
|
556
|
+
showCaddyLog && line && console.info(line);
|
|
557
|
+
if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
|
|
558
|
+
if (line.includes("parsing caddyfile tokens")) {
|
|
559
|
+
consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
|
|
560
|
+
|
|
561
|
+
${line}
|
|
562
|
+
`);
|
|
563
|
+
await this.baseCleanup();
|
|
564
|
+
import_node_process4.default.exit();
|
|
565
|
+
} else {
|
|
566
|
+
consola.error(`${line}
|
|
567
|
+
`);
|
|
568
|
+
return reject(line);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (line.includes("config file changed"))
|
|
572
|
+
consola.success("Detect added a new reverse proxy config, restarted.\n");
|
|
573
|
+
if (line.includes("caddy proxying") || line.includes("serving initial"))
|
|
574
|
+
return resolve();
|
|
466
575
|
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
576
|
+
});
|
|
577
|
+
(_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
|
|
578
|
+
consola.info(_data.toString());
|
|
579
|
+
resolve();
|
|
580
|
+
});
|
|
581
|
+
setupCleanup();
|
|
582
|
+
} else {
|
|
583
|
+
consola.info("Caddy is running in another process.");
|
|
584
|
+
setupCleanup();
|
|
585
|
+
return resolve();
|
|
586
|
+
}
|
|
473
587
|
});
|
|
474
588
|
}
|
|
589
|
+
async baseCleanup(restore = true) {
|
|
590
|
+
var _a;
|
|
591
|
+
try {
|
|
592
|
+
if (restore && this._source && this._target) {
|
|
593
|
+
if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
|
|
594
|
+
consola.success("Restore host success.\n");
|
|
595
|
+
else
|
|
596
|
+
consola.fail("Restore host failed.\n");
|
|
597
|
+
}
|
|
598
|
+
} catch (e) {
|
|
599
|
+
consola.error(e);
|
|
600
|
+
consola.fail("Restore host failed.\n");
|
|
601
|
+
}
|
|
602
|
+
if (!this.locked && !this.stoped) {
|
|
603
|
+
(_a = this._caddyChild) == null ? void 0 : _a.kill();
|
|
604
|
+
try {
|
|
605
|
+
await lockfile.unlock(caddyLockFilePath).catch(() => {
|
|
606
|
+
});
|
|
607
|
+
await (0, import_promises2.unlink)(caddyFilePath).catch(() => {
|
|
608
|
+
});
|
|
609
|
+
await (0, import_promises2.unlink)(caddyLockFilePath).catch(() => {
|
|
610
|
+
});
|
|
611
|
+
} catch (e) {
|
|
612
|
+
consola.error(e);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
475
616
|
};
|
|
476
617
|
|
|
477
618
|
// src/index.ts
|
|
478
|
-
var config;
|
|
479
619
|
var caddy;
|
|
480
|
-
var
|
|
481
|
-
|
|
620
|
+
var cwd = import_node_process5.default.cwd();
|
|
621
|
+
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
482
622
|
_printUrls == null ? void 0 : _printUrls();
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
consola.error(e);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
var unpluginFactory = (options) => ({
|
|
506
|
-
name: "unplugin-https-reverse-proxy",
|
|
507
|
-
enforce: "pre",
|
|
508
|
-
vite: {
|
|
509
|
-
configResolved(_config) {
|
|
510
|
-
config = _config;
|
|
511
|
-
},
|
|
512
|
-
configureServer(server) {
|
|
513
|
-
var _a;
|
|
514
|
-
if (!isAdmin()) {
|
|
515
|
-
consola.warn("please run as administrator");
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
if (config.command === "build")
|
|
519
|
-
return;
|
|
520
|
-
const {
|
|
521
|
-
enable = true,
|
|
522
|
-
target = ""
|
|
523
|
-
} = options;
|
|
524
|
-
if (!enable)
|
|
525
|
-
return;
|
|
526
|
-
if (!target) {
|
|
527
|
-
consola.fail("please provide target");
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const _printUrls = server.printUrls.bind(server);
|
|
531
|
-
let source = `localhost:${config.server.port || 5173}`;
|
|
532
|
-
const url = (_a = server.resolvedUrls) == null ? void 0 : _a.local[0];
|
|
533
|
-
if (url) {
|
|
534
|
-
const u = new URL(url);
|
|
535
|
-
source = u.host;
|
|
536
|
-
}
|
|
537
|
-
const base = server.config.base || "/";
|
|
538
|
-
server.printUrls = () => vitePrintUrls(server, options, source, target, base, _printUrls);
|
|
539
|
-
}
|
|
623
|
+
if (caddy)
|
|
624
|
+
return;
|
|
625
|
+
caddy = new CaddyInstant();
|
|
626
|
+
caddy.run(source, target, {
|
|
627
|
+
base,
|
|
628
|
+
...options
|
|
629
|
+
}).then(() => {
|
|
630
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
631
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
632
|
+
}).catch((e) => {
|
|
633
|
+
throw e;
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
// src/nuxt.ts
|
|
638
|
+
var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
639
|
+
meta: {
|
|
640
|
+
name: "nuxt-unplugin-https-reverse-proxy",
|
|
641
|
+
configKey: "unpluginHttpsReverseProxy"
|
|
540
642
|
},
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
if (!isAdmin()) {
|
|
544
|
-
consola.warn("please run as administrator");
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
643
|
+
setup(options, _nuxt) {
|
|
644
|
+
if (import_node_process6.default.env.NODE_ENV !== "development")
|
|
548
645
|
return;
|
|
549
646
|
const {
|
|
550
647
|
enable = true,
|
|
@@ -552,76 +649,20 @@ var unpluginFactory = (options) => ({
|
|
|
552
649
|
} = options;
|
|
553
650
|
if (!enable)
|
|
554
651
|
return;
|
|
652
|
+
if (!isAdmin()) {
|
|
653
|
+
consola.warn("please run as administrator");
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
555
656
|
if (!target) {
|
|
556
657
|
consola.fail("please provide target");
|
|
557
658
|
return;
|
|
558
659
|
}
|
|
559
|
-
const nuxtCacheDir = `${pwd}/node_modules/.cache`;
|
|
560
|
-
if ((0, import_node_fs3.existsSync)(nuxtCacheDir))
|
|
561
|
-
chmodRecursive(nuxtCacheDir, 511);
|
|
562
|
-
try {
|
|
563
|
-
const devServer = __spreadValues(__spreadValues({
|
|
564
|
-
host: "localhost",
|
|
565
|
-
port: 8080
|
|
566
|
-
}, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
567
|
-
const source = `${devServer.host}:${devServer.port}`;
|
|
568
|
-
if (caddy)
|
|
569
|
-
return;
|
|
570
|
-
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
571
|
-
if (_close) {
|
|
572
|
-
compiler.close = async (callback) => {
|
|
573
|
-
import_node_process5.default.on("exit", () => {
|
|
574
|
-
_close && _close(callback);
|
|
575
|
-
});
|
|
576
|
-
};
|
|
577
|
-
} else {
|
|
578
|
-
options.https = false;
|
|
579
|
-
}
|
|
580
|
-
caddy = new CaddyInstant();
|
|
581
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
582
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
583
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
584
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
585
|
-
});
|
|
586
|
-
}).catch((e) => {
|
|
587
|
-
throw e;
|
|
588
|
-
});
|
|
589
|
-
} catch (e) {
|
|
590
|
-
consola.error(e);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
// src/vite.ts
|
|
596
|
-
var vite_default = (0, import_unplugin2.createVitePlugin)(unpluginFactory);
|
|
597
|
-
|
|
598
|
-
// src/webpack.ts
|
|
599
|
-
var import_unplugin3 = require("unplugin");
|
|
600
|
-
var webpack_default = (0, import_unplugin3.createWebpackPlugin)(unpluginFactory);
|
|
601
|
-
|
|
602
|
-
// src/nuxt.ts
|
|
603
|
-
var import_schema = require("@nuxt/schema");
|
|
604
|
-
var nuxt_default = (0, import_kit.defineNuxtModule)({
|
|
605
|
-
meta: {
|
|
606
|
-
name: "nuxt-unplugin-https-reverse-proxy",
|
|
607
|
-
configKey: "unpluginHttpsReverseProxy"
|
|
608
|
-
},
|
|
609
|
-
setup(options, _nuxt) {
|
|
610
|
-
(0, import_kit.addVitePlugin)(() => vite_default(options));
|
|
611
|
-
(0, import_kit.addWebpackPlugin)(() => webpack_default(options));
|
|
612
|
-
let url = "";
|
|
613
660
|
_nuxt.hook("listen", (_, listener) => {
|
|
614
|
-
url = listener.url;
|
|
615
|
-
});
|
|
616
|
-
_nuxt.hook("vite:serverCreated", once((server) => {
|
|
661
|
+
const url = listener.url;
|
|
617
662
|
const source = new URL(url).host;
|
|
618
|
-
if (!options.target) {
|
|
619
|
-
consola.fail("please provide target");
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
663
|
const base = _nuxt.options.app.baseURL || "/";
|
|
623
|
-
vitePrintUrls(
|
|
624
|
-
})
|
|
664
|
+
vitePrintUrls(options, source, options.target, base);
|
|
665
|
+
});
|
|
625
666
|
}
|
|
626
667
|
});
|
|
627
|
-
exports.default = module.exports;
|
|
668
|
+
module.exports = module.exports;exports.default = module.exports;
|