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