unplugin-https-reverse-proxy 0.0.12 → 0.0.13
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 +2 -0
- package/dist/{chunk-YP6CZ57A.js → chunk-6KXUNICB.js} +1 -1
- package/dist/chunk-CQC5SSJR.js +37 -0
- package/dist/{chunk-WUSTJHAZ.js → chunk-DH6VMKTP.js} +172 -69
- package/dist/{chunk-ARWX57QE.js → chunk-RTEXFW4L.js} +1 -1
- package/dist/esbuild.cjs +191 -67
- package/dist/esbuild.js +2 -2
- package/dist/index.cjs +191 -67
- package/dist/index.js +2 -2
- package/dist/nuxt.cjs +191 -67
- package/dist/nuxt.js +4 -4
- package/dist/rollup.cjs +191 -67
- package/dist/rollup.js +2 -2
- package/dist/utils.cjs +13 -2
- package/dist/utils.d.cts +2 -1
- package/dist/utils.d.ts +2 -1
- package/dist/utils.js +5 -3
- package/dist/vite.cjs +191 -67
- package/dist/vite.js +3 -3
- package/dist/webpack.cjs +191 -67
- package/dist/webpack.js +3 -3
- package/package.json +3 -3
- package/src/caddy/index.ts +68 -57
- package/src/caddy/utils.ts +41 -0
- package/src/index.ts +95 -21
- package/src/utils.ts +10 -0
- package/dist/chunk-3HKPYCSE.js +0 -9
package/dist/nuxt.cjs
CHANGED
|
@@ -3,8 +3,22 @@ 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;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
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
|
+
};
|
|
8
22
|
var __export = (target, all) => {
|
|
9
23
|
for (var name in all)
|
|
10
24
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -48,6 +62,15 @@ var import_consola = require("consola");
|
|
|
48
62
|
var consola = (0, import_consola.createConsola)({
|
|
49
63
|
level: 3
|
|
50
64
|
}).withTag("reverse-proxy");
|
|
65
|
+
function once(fn) {
|
|
66
|
+
let called = false;
|
|
67
|
+
return (...args) => {
|
|
68
|
+
if (called)
|
|
69
|
+
return;
|
|
70
|
+
called = true;
|
|
71
|
+
return fn(...args);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
51
74
|
|
|
52
75
|
// src/caddy/index.ts
|
|
53
76
|
var import_node_os = require("os");
|
|
@@ -57,7 +80,7 @@ var import_node_child_process = require("child_process");
|
|
|
57
80
|
var import_got_cjs = require("got-cjs");
|
|
58
81
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
59
82
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
60
|
-
var
|
|
83
|
+
var import_hosts_so_easy = __toESM(require("hosts-so-easy"), 1);
|
|
61
84
|
var import_kill_port = __toESM(require("kill-port"), 1);
|
|
62
85
|
|
|
63
86
|
// src/caddy/constants.ts
|
|
@@ -179,6 +202,8 @@ var supportList = [
|
|
|
179
202
|
|
|
180
203
|
// src/caddy/utils.ts
|
|
181
204
|
var import_node_net = require("net");
|
|
205
|
+
var import_ora = __toESM(require("ora"), 1);
|
|
206
|
+
var spinner;
|
|
182
207
|
function tryPort(port) {
|
|
183
208
|
return new Promise((resolve, reject) => {
|
|
184
209
|
try {
|
|
@@ -197,8 +222,41 @@ function tryPort(port) {
|
|
|
197
222
|
}
|
|
198
223
|
});
|
|
199
224
|
}
|
|
225
|
+
function getNumber(number) {
|
|
226
|
+
if (number <= 0)
|
|
227
|
+
return "0%";
|
|
228
|
+
else if (number < 100)
|
|
229
|
+
return `${number.toFixed(2)}%`;
|
|
230
|
+
else
|
|
231
|
+
return "100%";
|
|
232
|
+
}
|
|
233
|
+
function logProgress(percent) {
|
|
234
|
+
if (!spinner) {
|
|
235
|
+
consola.log("");
|
|
236
|
+
spinner = (0, import_ora.default)({
|
|
237
|
+
text: "Start Download Caddy: 0%",
|
|
238
|
+
indent: 2
|
|
239
|
+
});
|
|
240
|
+
spinner.start();
|
|
241
|
+
} else {
|
|
242
|
+
spinner.text = `Download Caddy: ${getNumber(Number(percent) * 100)}`;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function logProgressOver() {
|
|
246
|
+
if (!spinner) {
|
|
247
|
+
spinner = (0, import_ora.default)({
|
|
248
|
+
text: "Start Download Caddy: 100%",
|
|
249
|
+
indent: 2
|
|
250
|
+
});
|
|
251
|
+
spinner.start();
|
|
252
|
+
} else {
|
|
253
|
+
spinner.succeed();
|
|
254
|
+
consola.log("");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
200
257
|
|
|
201
258
|
// src/caddy/index.ts
|
|
259
|
+
var Hosts = import_hosts_so_easy.default.default || import_hosts_so_easy.default;
|
|
202
260
|
async function download() {
|
|
203
261
|
if (await testCaddy())
|
|
204
262
|
return caddyPath;
|
|
@@ -222,7 +280,10 @@ async function download() {
|
|
|
222
280
|
http: httpAgent,
|
|
223
281
|
https: httpsAgent
|
|
224
282
|
}
|
|
283
|
+
}).on("downloadProgress", (progress) => {
|
|
284
|
+
logProgress(progress.percent);
|
|
225
285
|
}).pipe(file).on("finish", () => {
|
|
286
|
+
logProgressOver();
|
|
226
287
|
if (import_node_process2.default.platform === "win32")
|
|
227
288
|
return resolve(caddyPath);
|
|
228
289
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
@@ -237,7 +298,7 @@ function testCaddy() {
|
|
|
237
298
|
if (!(0, import_node_fs.existsSync)(caddyPath))
|
|
238
299
|
return resolve(false);
|
|
239
300
|
(0, import_node_fs.chmodSync)(caddyPath, 493);
|
|
240
|
-
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", [caddyPath]);
|
|
301
|
+
const child = import_node_process2.default.platform === "win32" ? (0, import_node_child_process.spawn)(caddyPath, []) : (0, import_node_child_process.spawn)("sudo", ["-E", caddyPath]);
|
|
241
302
|
child.on("close", () => {
|
|
242
303
|
return resolve(false);
|
|
243
304
|
});
|
|
@@ -252,6 +313,8 @@ function testCaddy() {
|
|
|
252
313
|
var CaddyInstant = class {
|
|
253
314
|
constructor() {
|
|
254
315
|
this.inited = false;
|
|
316
|
+
this.stoped = false;
|
|
317
|
+
this.host = new Hosts();
|
|
255
318
|
testCaddy().then(() => {
|
|
256
319
|
this.inited = true;
|
|
257
320
|
});
|
|
@@ -260,52 +323,46 @@ var CaddyInstant = class {
|
|
|
260
323
|
await download();
|
|
261
324
|
this.inited = true;
|
|
262
325
|
}
|
|
263
|
-
|
|
326
|
+
updateHost(ip, host) {
|
|
264
327
|
["localhost", "0.0.0.0"].includes(ip) && (ip = "127.0.0.1");
|
|
328
|
+
this.host.add(ip, host);
|
|
265
329
|
return new Promise((resolve, reject) => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
});
|
|
330
|
+
if (import_node_process2.default.platform === "win32") {
|
|
331
|
+
(0, import_node_child_process.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
332
|
+
consola.error(err);
|
|
333
|
+
return resolve(false);
|
|
334
|
+
}).on("close", () => {
|
|
335
|
+
resolve(true);
|
|
336
|
+
});
|
|
337
|
+
} else {
|
|
338
|
+
(0, import_node_child_process.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
339
|
+
consola.error(err);
|
|
340
|
+
return resolve(false);
|
|
341
|
+
}).on("close", () => {
|
|
342
|
+
resolve(true);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
285
345
|
});
|
|
286
346
|
}
|
|
287
|
-
|
|
347
|
+
restoreHost(ip, host) {
|
|
288
348
|
["localhost", "0.0.0.0"].includes(ip) && (ip = "127.0.0.1");
|
|
349
|
+
this.host.remove(ip, host);
|
|
289
350
|
return new Promise((resolve, reject) => {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
351
|
+
if (import_node_process2.default.platform === "win32") {
|
|
352
|
+
(0, import_node_child_process.spawn)("ipconfig", ["/flushdns"]).on("error", (err) => {
|
|
353
|
+
consola.error(err);
|
|
354
|
+
return resolve(false);
|
|
355
|
+
}).on("close", () => {
|
|
356
|
+
resolve(true);
|
|
357
|
+
});
|
|
358
|
+
} else {
|
|
359
|
+
(0, import_node_child_process.spawn)("sudo", ["-E", "killall", "-HUP", "mDNSResponder"]).on("error", (err) => {
|
|
360
|
+
consola.error(err);
|
|
361
|
+
return resolve(false);
|
|
362
|
+
}).on("close", () => {
|
|
363
|
+
resolve(true);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
309
366
|
});
|
|
310
367
|
}
|
|
311
368
|
/**
|
|
@@ -322,14 +379,15 @@ var CaddyInstant = class {
|
|
|
322
379
|
} = options || {};
|
|
323
380
|
if (!this.inited)
|
|
324
381
|
await this.init();
|
|
325
|
-
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
326
|
-
throw new Error("update host failed");
|
|
327
382
|
if (await tryPort(443))
|
|
328
383
|
await (0, import_kill_port.default)(443, "tcp");
|
|
329
384
|
if (import_node_process2.default.platform === "win32" && await tryPort(80))
|
|
330
385
|
await (0, import_kill_port.default)(80, "tcp");
|
|
386
|
+
if (!await this.updateHost(source.split(":")[0], target.split(":")[0]))
|
|
387
|
+
throw new Error("update host failed");
|
|
388
|
+
consola.success("update host success\n");
|
|
331
389
|
return new Promise((resolve, reject) => {
|
|
332
|
-
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", [caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
390
|
+
const child = import_node_process2.default.platform !== "win32" ? (0, import_node_child_process.spawn)("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]) : (0, import_node_child_process.spawn)(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
|
|
333
391
|
child.on("error", (err) => {
|
|
334
392
|
return reject(err);
|
|
335
393
|
});
|
|
@@ -345,14 +403,21 @@ var CaddyInstant = class {
|
|
|
345
403
|
});
|
|
346
404
|
child.stdout.on("data", (_data) => {
|
|
347
405
|
consola.info(_data.toString());
|
|
348
|
-
resolve(async () => {
|
|
349
|
-
if (!restore)
|
|
406
|
+
resolve(async (callback) => {
|
|
407
|
+
if (!restore || this.stoped)
|
|
350
408
|
return;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
409
|
+
try {
|
|
410
|
+
if (await this.restoreHost(source.split(":")[0], target.split(":")[0]))
|
|
411
|
+
consola.success("restore host success\n");
|
|
412
|
+
else
|
|
413
|
+
consola.fail("restore host failed\n");
|
|
414
|
+
} catch (e) {
|
|
415
|
+
consola.error(e);
|
|
354
416
|
consola.fail("restore host failed\n");
|
|
417
|
+
}
|
|
418
|
+
this.stoped = true;
|
|
355
419
|
child.kill();
|
|
420
|
+
callback && callback();
|
|
356
421
|
});
|
|
357
422
|
});
|
|
358
423
|
});
|
|
@@ -362,12 +427,53 @@ var CaddyInstant = class {
|
|
|
362
427
|
// src/index.ts
|
|
363
428
|
var config;
|
|
364
429
|
var caddy;
|
|
430
|
+
var _stop;
|
|
431
|
+
var _servce;
|
|
432
|
+
function registerExit(clear) {
|
|
433
|
+
import_node_process3.default.on("beforeExit", async (_code) => {
|
|
434
|
+
await clear();
|
|
435
|
+
});
|
|
436
|
+
import_node_process3.default.on("uncaughtException", async (err) => {
|
|
437
|
+
console.error("An uncaught error occurred!", err.stack);
|
|
438
|
+
await clear();
|
|
439
|
+
import_node_process3.default.nextTick(() => {
|
|
440
|
+
import_node_process3.default.exit(1);
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
import_node_process3.default.on("unhandledRejection", async (reason, promise) => {
|
|
444
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
445
|
+
await clear();
|
|
446
|
+
import_node_process3.default.nextTick(() => {
|
|
447
|
+
import_node_process3.default.exit(1);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
import_node_process3.default.once("SIGINT", async () => {
|
|
451
|
+
await clear();
|
|
452
|
+
import_node_process3.default.emit("SIGINT");
|
|
453
|
+
});
|
|
454
|
+
import_node_process3.default.once("SIGTERM", async () => {
|
|
455
|
+
await clear();
|
|
456
|
+
import_node_process3.default.emit("SIGTERM");
|
|
457
|
+
});
|
|
458
|
+
}
|
|
365
459
|
var unpluginFactory = (options) => ({
|
|
366
460
|
name: "unplugin-https-reverse-proxy",
|
|
367
|
-
enforce: "
|
|
461
|
+
enforce: "pre",
|
|
368
462
|
vite: {
|
|
369
463
|
configResolved(_config) {
|
|
370
464
|
config = _config;
|
|
465
|
+
registerExit(async () => {
|
|
466
|
+
var _a;
|
|
467
|
+
try {
|
|
468
|
+
_servce && _servce.close();
|
|
469
|
+
(_a = _servce.httpServer) == null ? void 0 : _a.close(async () => {
|
|
470
|
+
_stop && await _stop();
|
|
471
|
+
});
|
|
472
|
+
_stop && await _stop();
|
|
473
|
+
} catch (e) {
|
|
474
|
+
consola.error(e);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
371
477
|
},
|
|
372
478
|
configureServer(server) {
|
|
373
479
|
const {
|
|
@@ -380,6 +486,7 @@ var unpluginFactory = (options) => ({
|
|
|
380
486
|
consola.fail("please provide target");
|
|
381
487
|
return;
|
|
382
488
|
}
|
|
489
|
+
_servce = server;
|
|
383
490
|
const _printUrls = server.printUrls;
|
|
384
491
|
server.printUrls = () => {
|
|
385
492
|
var _a;
|
|
@@ -392,18 +499,16 @@ var unpluginFactory = (options) => ({
|
|
|
392
499
|
}
|
|
393
500
|
const base = server.config.base || "/";
|
|
394
501
|
try {
|
|
395
|
-
|
|
396
|
-
|
|
502
|
+
if (caddy)
|
|
503
|
+
return;
|
|
504
|
+
caddy = new CaddyInstant();
|
|
505
|
+
caddy.run(source, target, {
|
|
397
506
|
base,
|
|
398
507
|
showCaddyLog: options.showCaddyLog
|
|
399
508
|
}).then((stop) => {
|
|
400
509
|
const colorUrl = (url2) => import_picocolors.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
401
510
|
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}${base}`)}`);
|
|
402
|
-
|
|
403
|
-
await stop();
|
|
404
|
-
server.close();
|
|
405
|
-
import_node_process3.default.exit();
|
|
406
|
-
});
|
|
511
|
+
!_stop && (_stop = once(stop));
|
|
407
512
|
}).catch((e) => {
|
|
408
513
|
throw e;
|
|
409
514
|
});
|
|
@@ -411,6 +516,9 @@ var unpluginFactory = (options) => ({
|
|
|
411
516
|
consola.error(e);
|
|
412
517
|
}
|
|
413
518
|
};
|
|
519
|
+
},
|
|
520
|
+
async buildEnd() {
|
|
521
|
+
_stop && await _stop();
|
|
414
522
|
}
|
|
415
523
|
},
|
|
416
524
|
webpack(compiler) {
|
|
@@ -425,23 +533,39 @@ var unpluginFactory = (options) => ({
|
|
|
425
533
|
return;
|
|
426
534
|
}
|
|
427
535
|
try {
|
|
428
|
-
|
|
429
|
-
|
|
536
|
+
registerExit(async () => {
|
|
537
|
+
try {
|
|
538
|
+
_stop && await _stop();
|
|
539
|
+
} catch (e) {
|
|
540
|
+
consola.error(e);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
const devServer = __spreadValues(__spreadValues({
|
|
544
|
+
host: "127.0.0.1",
|
|
545
|
+
port: 8080
|
|
546
|
+
}, compiler.options.devServer), import_node_process3.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
547
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
430
548
|
if (caddy)
|
|
431
549
|
return;
|
|
550
|
+
const _close = compiler.close.bind(compiler);
|
|
551
|
+
compiler.close = async (callback) => {
|
|
552
|
+
try {
|
|
553
|
+
_stop && await _stop(() => {
|
|
554
|
+
_close && _close(callback);
|
|
555
|
+
});
|
|
556
|
+
} catch (e) {
|
|
557
|
+
consola.error(e);
|
|
558
|
+
import_node_process3.default.exit(1);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
432
561
|
caddy = new CaddyInstant();
|
|
433
562
|
caddy.run(source, target, {
|
|
434
563
|
showCaddyLog: options.showCaddyLog
|
|
435
564
|
}).then((stop) => {
|
|
436
565
|
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
437
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", (
|
|
438
|
-
if (stats.hasErrors())
|
|
439
|
-
return;
|
|
566
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
440
567
|
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`https://${target}`)}`);
|
|
441
|
-
|
|
442
|
-
import_node_process3.default.on("SIGINT", async () => {
|
|
443
|
-
await stop();
|
|
444
|
-
import_node_process3.default.exit();
|
|
568
|
+
!_stop && (_stop = once(stop));
|
|
445
569
|
});
|
|
446
570
|
}).catch((e) => {
|
|
447
571
|
throw e;
|
package/dist/nuxt.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6KXUNICB.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-RTEXFW4L.js";
|
|
7
|
+
import "./chunk-DH6VMKTP.js";
|
|
8
|
+
import "./chunk-CQC5SSJR.js";
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
|
11
11
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|