unplugin-https-reverse-proxy 1.0.0-beta.3 → 1.0.0-beta.6
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/dist/{chunk-ZAZWZOPZ.js → chunk-NBFRMP2Y.js} +63 -60
- package/dist/esbuild.cjs +62 -59
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +62 -59
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +36 -26
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +62 -59
- package/dist/rollup.js +1 -1
- package/dist/vite.cjs +62 -59
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +62 -59
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/constants.ts +1 -1
- package/src/caddy/index.ts +31 -4
- package/src/index.ts +51 -74
- package/src/nuxt.ts +3 -3
|
@@ -8,14 +8,13 @@ import {
|
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import process4 from "process";
|
|
11
|
-
import { existsSync as existsSync2 } from "fs";
|
|
12
11
|
import { createUnplugin } from "unplugin";
|
|
13
12
|
import c from "picocolors";
|
|
14
13
|
|
|
15
14
|
// src/caddy/index.ts
|
|
16
15
|
import { platform } from "os";
|
|
17
16
|
import process3 from "process";
|
|
18
|
-
import { chmodSync as chmodSync2, createWriteStream, existsSync, unlinkSync } from "fs";
|
|
17
|
+
import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync } from "fs";
|
|
19
18
|
import { spawn } from "child_process";
|
|
20
19
|
import { got } from "got-cjs";
|
|
21
20
|
import { HttpProxyAgent } from "http-proxy-agent";
|
|
@@ -72,7 +71,7 @@ async function removeHost(ip, host) {
|
|
|
72
71
|
// src/caddy/constants.ts
|
|
73
72
|
import { join } from "path";
|
|
74
73
|
import process2 from "process";
|
|
75
|
-
var TEMP_DIR = process2.env.TEMP || process2.env.TMPDIR || "/tmp";
|
|
74
|
+
var TEMP_DIR = process2.env.UHRP_CADDY_PATH || process2.env.TEMP || process2.env.TMPDIR || "/tmp";
|
|
76
75
|
var caddyPath = join(TEMP_DIR, `caddy${process2.platform === "win32" ? ".exe" : ""}`);
|
|
77
76
|
var caddyFilePath = join(TEMP_DIR, "CADDYFILE");
|
|
78
77
|
var supportList = [
|
|
@@ -246,6 +245,10 @@ async function download() {
|
|
|
246
245
|
if (await testCaddy())
|
|
247
246
|
return caddyPath;
|
|
248
247
|
return new Promise((resolve, reject) => {
|
|
248
|
+
if (!existsSync(TEMP_DIR)) {
|
|
249
|
+
mkdirSync(TEMP_DIR, { recursive: true });
|
|
250
|
+
chmodSync2(TEMP_DIR, 511);
|
|
251
|
+
}
|
|
249
252
|
const file = createWriteStream(caddyPath);
|
|
250
253
|
let _platform = platform().toString();
|
|
251
254
|
_platform === "win32" && (_platform = "windows");
|
|
@@ -260,6 +263,9 @@ async function download() {
|
|
|
260
263
|
const httpsProxy = process3.env.HTTPS_PROXY || process3.env.https_proxy;
|
|
261
264
|
const httpAgent = httpProxy ? new HttpProxyAgent(httpProxy) : void 0;
|
|
262
265
|
const httpsAgent = httpsProxy ? new HttpsProxyAgent(httpsProxy) : void 0;
|
|
266
|
+
const chmodCaddyOnce = once(() => {
|
|
267
|
+
chmodSync2(caddyPath, 511);
|
|
268
|
+
});
|
|
263
269
|
got.stream(dowmloadLink, {
|
|
264
270
|
agent: {
|
|
265
271
|
http: httpAgent,
|
|
@@ -267,11 +273,12 @@ async function download() {
|
|
|
267
273
|
}
|
|
268
274
|
}).on("downloadProgress", (progress) => {
|
|
269
275
|
logProgress(progress.percent);
|
|
276
|
+
chmodCaddyOnce();
|
|
270
277
|
}).pipe(file).on("finish", () => {
|
|
271
278
|
logProgressOver();
|
|
272
279
|
if (process3.platform === "win32")
|
|
273
280
|
return resolve(caddyPath);
|
|
274
|
-
chmodSync2(caddyPath,
|
|
281
|
+
chmodSync2(caddyPath, 511);
|
|
275
282
|
resolve(caddyPath);
|
|
276
283
|
}).on("error", (err) => {
|
|
277
284
|
reject(err);
|
|
@@ -354,6 +361,19 @@ var CaddyInstant = class {
|
|
|
354
361
|
});
|
|
355
362
|
const originalExit = process3.exit.bind(process3);
|
|
356
363
|
process3.exit = async (code) => {
|
|
364
|
+
const port = Number(source.split(":")[1]);
|
|
365
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
366
|
+
await kill(port, "tcp");
|
|
367
|
+
const pwd2 = process3.cwd();
|
|
368
|
+
const viteCacheDir = `${pwd2}/node_modules/.vite`;
|
|
369
|
+
if (existsSync(viteCacheDir))
|
|
370
|
+
chmodRecursive(viteCacheDir, 511);
|
|
371
|
+
const nuxtCacheDir = `${pwd2}/.nuxt`;
|
|
372
|
+
if (existsSync(nuxtCacheDir))
|
|
373
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
374
|
+
const webpackCacheDir = `${pwd2}/node_modules/.cache`;
|
|
375
|
+
if (existsSync(webpackCacheDir))
|
|
376
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
357
377
|
if (!restore || this.stoped)
|
|
358
378
|
return originalExit(code);
|
|
359
379
|
try {
|
|
@@ -395,27 +415,17 @@ var caddy;
|
|
|
395
415
|
var pwd = process4.cwd();
|
|
396
416
|
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
397
417
|
_printUrls == null ? void 0 : _printUrls();
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
base
|
|
410
|
-
}, options)).then(() => {
|
|
411
|
-
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
412
|
-
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
413
|
-
}).catch((e) => {
|
|
414
|
-
throw e;
|
|
415
|
-
});
|
|
416
|
-
} catch (e) {
|
|
417
|
-
consola.error(e);
|
|
418
|
-
}
|
|
418
|
+
if (caddy)
|
|
419
|
+
return;
|
|
420
|
+
caddy = new CaddyInstant();
|
|
421
|
+
caddy.run(source, target, __spreadValues({
|
|
422
|
+
base
|
|
423
|
+
}, options)).then(() => {
|
|
424
|
+
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
425
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
426
|
+
}).catch((e) => {
|
|
427
|
+
throw e;
|
|
428
|
+
});
|
|
419
429
|
});
|
|
420
430
|
var unpluginFactory = (options) => ({
|
|
421
431
|
name: "unplugin-https-reverse-proxy",
|
|
@@ -426,12 +436,12 @@ var unpluginFactory = (options) => ({
|
|
|
426
436
|
},
|
|
427
437
|
configureServer(server) {
|
|
428
438
|
var _a;
|
|
439
|
+
if (config.command !== "serve")
|
|
440
|
+
return;
|
|
429
441
|
if (!isAdmin()) {
|
|
430
442
|
consola.warn("please run as administrator");
|
|
431
443
|
return;
|
|
432
444
|
}
|
|
433
|
-
if (config.command === "build")
|
|
434
|
-
return;
|
|
435
445
|
const {
|
|
436
446
|
enable = true,
|
|
437
447
|
target = ""
|
|
@@ -455,12 +465,12 @@ var unpluginFactory = (options) => ({
|
|
|
455
465
|
},
|
|
456
466
|
webpack(compiler) {
|
|
457
467
|
var _a;
|
|
468
|
+
if (process4.env.NODE_ENV !== "development")
|
|
469
|
+
return;
|
|
458
470
|
if (!isAdmin()) {
|
|
459
471
|
consola.warn("please run as administrator");
|
|
460
472
|
return;
|
|
461
473
|
}
|
|
462
|
-
if (process4.env.NODE_ENV !== "development")
|
|
463
|
-
return;
|
|
464
474
|
const {
|
|
465
475
|
enable = true,
|
|
466
476
|
target = ""
|
|
@@ -471,39 +481,32 @@ var unpluginFactory = (options) => ({
|
|
|
471
481
|
consola.fail("please provide target");
|
|
472
482
|
return;
|
|
473
483
|
}
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
if (_close) {
|
|
487
|
-
compiler.close = async (callback) => {
|
|
488
|
-
process4.on("exit", () => {
|
|
489
|
-
_close && _close(callback);
|
|
490
|
-
});
|
|
491
|
-
};
|
|
492
|
-
} else {
|
|
493
|
-
options.https = false;
|
|
494
|
-
}
|
|
495
|
-
caddy = new CaddyInstant();
|
|
496
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
497
|
-
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
498
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
499
|
-
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
484
|
+
const devServer = __spreadValues(__spreadValues({
|
|
485
|
+
host: "localhost",
|
|
486
|
+
port: 8080
|
|
487
|
+
}, compiler.options.devServer), process4.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
488
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
489
|
+
if (caddy)
|
|
490
|
+
return;
|
|
491
|
+
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
492
|
+
if (_close) {
|
|
493
|
+
compiler.close = async (callback) => {
|
|
494
|
+
process4.on("exit", () => {
|
|
495
|
+
_close && _close(callback);
|
|
500
496
|
});
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
} catch (e) {
|
|
505
|
-
consola.error(e);
|
|
497
|
+
};
|
|
498
|
+
} else {
|
|
499
|
+
options.https = false;
|
|
506
500
|
}
|
|
501
|
+
caddy = new CaddyInstant();
|
|
502
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
503
|
+
const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
|
|
504
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
505
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
506
|
+
});
|
|
507
|
+
}).catch((e) => {
|
|
508
|
+
throw e;
|
|
509
|
+
});
|
|
507
510
|
}
|
|
508
511
|
});
|
|
509
512
|
var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
package/dist/esbuild.cjs
CHANGED
|
@@ -51,7 +51,6 @@ 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
|
|
|
@@ -154,7 +153,7 @@ async function removeHost(ip, host) {
|
|
|
154
153
|
// src/caddy/constants.ts
|
|
155
154
|
var import_node_path2 = require("path");
|
|
156
155
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
157
|
-
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
156
|
+
var TEMP_DIR = import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
158
157
|
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
159
158
|
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
160
159
|
var supportList = [
|
|
@@ -328,6 +327,10 @@ async function download() {
|
|
|
328
327
|
if (await testCaddy())
|
|
329
328
|
return caddyPath;
|
|
330
329
|
return new Promise((resolve, reject) => {
|
|
330
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
331
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
332
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
333
|
+
}
|
|
331
334
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
332
335
|
let _platform = (0, import_node_os.platform)().toString();
|
|
333
336
|
_platform === "win32" && (_platform = "windows");
|
|
@@ -342,6 +345,9 @@ async function download() {
|
|
|
342
345
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
343
346
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
344
347
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
348
|
+
const chmodCaddyOnce = once(() => {
|
|
349
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
350
|
+
});
|
|
345
351
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
346
352
|
agent: {
|
|
347
353
|
http: httpAgent,
|
|
@@ -349,11 +355,12 @@ async function download() {
|
|
|
349
355
|
}
|
|
350
356
|
}).on("downloadProgress", (progress) => {
|
|
351
357
|
logProgress(progress.percent);
|
|
358
|
+
chmodCaddyOnce();
|
|
352
359
|
}).pipe(file).on("finish", () => {
|
|
353
360
|
logProgressOver();
|
|
354
361
|
if (import_node_process4.default.platform === "win32")
|
|
355
362
|
return resolve(caddyPath);
|
|
356
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
363
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
357
364
|
resolve(caddyPath);
|
|
358
365
|
}).on("error", (err) => {
|
|
359
366
|
reject(err);
|
|
@@ -436,6 +443,19 @@ var CaddyInstant = class {
|
|
|
436
443
|
});
|
|
437
444
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
438
445
|
import_node_process4.default.exit = async (code) => {
|
|
446
|
+
const port = Number(source.split(":")[1]);
|
|
447
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
448
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
449
|
+
const pwd2 = import_node_process4.default.cwd();
|
|
450
|
+
const viteCacheDir = `${pwd2}/node_modules/.vite`;
|
|
451
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
452
|
+
chmodRecursive(viteCacheDir, 511);
|
|
453
|
+
const nuxtCacheDir = `${pwd2}/.nuxt`;
|
|
454
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
455
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
456
|
+
const webpackCacheDir = `${pwd2}/node_modules/.cache`;
|
|
457
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
458
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
439
459
|
if (!restore || this.stoped)
|
|
440
460
|
return originalExit(code);
|
|
441
461
|
try {
|
|
@@ -477,27 +497,17 @@ var caddy;
|
|
|
477
497
|
var pwd = import_node_process5.default.cwd();
|
|
478
498
|
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
479
499
|
_printUrls == null ? void 0 : _printUrls();
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
base
|
|
492
|
-
}, options)).then(() => {
|
|
493
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
494
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
495
|
-
}).catch((e) => {
|
|
496
|
-
throw e;
|
|
497
|
-
});
|
|
498
|
-
} catch (e) {
|
|
499
|
-
consola.error(e);
|
|
500
|
-
}
|
|
500
|
+
if (caddy)
|
|
501
|
+
return;
|
|
502
|
+
caddy = new CaddyInstant();
|
|
503
|
+
caddy.run(source, target, __spreadValues({
|
|
504
|
+
base
|
|
505
|
+
}, options)).then(() => {
|
|
506
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
507
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
508
|
+
}).catch((e) => {
|
|
509
|
+
throw e;
|
|
510
|
+
});
|
|
501
511
|
});
|
|
502
512
|
var unpluginFactory = (options) => ({
|
|
503
513
|
name: "unplugin-https-reverse-proxy",
|
|
@@ -508,12 +518,12 @@ var unpluginFactory = (options) => ({
|
|
|
508
518
|
},
|
|
509
519
|
configureServer(server) {
|
|
510
520
|
var _a;
|
|
521
|
+
if (config.command !== "serve")
|
|
522
|
+
return;
|
|
511
523
|
if (!isAdmin()) {
|
|
512
524
|
consola.warn("please run as administrator");
|
|
513
525
|
return;
|
|
514
526
|
}
|
|
515
|
-
if (config.command === "build")
|
|
516
|
-
return;
|
|
517
527
|
const {
|
|
518
528
|
enable = true,
|
|
519
529
|
target = ""
|
|
@@ -537,12 +547,12 @@ var unpluginFactory = (options) => ({
|
|
|
537
547
|
},
|
|
538
548
|
webpack(compiler) {
|
|
539
549
|
var _a;
|
|
550
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
551
|
+
return;
|
|
540
552
|
if (!isAdmin()) {
|
|
541
553
|
consola.warn("please run as administrator");
|
|
542
554
|
return;
|
|
543
555
|
}
|
|
544
|
-
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
545
|
-
return;
|
|
546
556
|
const {
|
|
547
557
|
enable = true,
|
|
548
558
|
target = ""
|
|
@@ -553,39 +563,32 @@ var unpluginFactory = (options) => ({
|
|
|
553
563
|
consola.fail("please provide target");
|
|
554
564
|
return;
|
|
555
565
|
}
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (_close) {
|
|
569
|
-
compiler.close = async (callback) => {
|
|
570
|
-
import_node_process5.default.on("exit", () => {
|
|
571
|
-
_close && _close(callback);
|
|
572
|
-
});
|
|
573
|
-
};
|
|
574
|
-
} else {
|
|
575
|
-
options.https = false;
|
|
576
|
-
}
|
|
577
|
-
caddy = new CaddyInstant();
|
|
578
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
579
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
580
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
581
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
566
|
+
const devServer = __spreadValues(__spreadValues({
|
|
567
|
+
host: "localhost",
|
|
568
|
+
port: 8080
|
|
569
|
+
}, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
570
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
571
|
+
if (caddy)
|
|
572
|
+
return;
|
|
573
|
+
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
574
|
+
if (_close) {
|
|
575
|
+
compiler.close = async (callback) => {
|
|
576
|
+
import_node_process5.default.on("exit", () => {
|
|
577
|
+
_close && _close(callback);
|
|
582
578
|
});
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
} catch (e) {
|
|
587
|
-
consola.error(e);
|
|
579
|
+
};
|
|
580
|
+
} else {
|
|
581
|
+
options.https = false;
|
|
588
582
|
}
|
|
583
|
+
caddy = new CaddyInstant();
|
|
584
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
585
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
586
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
587
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
588
|
+
});
|
|
589
|
+
}).catch((e) => {
|
|
590
|
+
throw e;
|
|
591
|
+
});
|
|
589
592
|
}
|
|
590
593
|
});
|
|
591
594
|
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,6 @@ __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
|
|
|
@@ -154,7 +153,7 @@ async function removeHost(ip, host) {
|
|
|
154
153
|
// src/caddy/constants.ts
|
|
155
154
|
var import_node_path2 = require("path");
|
|
156
155
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
157
|
-
var TEMP_DIR = import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
156
|
+
var TEMP_DIR = import_node_process3.default.env.UHRP_CADDY_PATH || import_node_process3.default.env.TEMP || import_node_process3.default.env.TMPDIR || "/tmp";
|
|
158
157
|
var caddyPath = (0, import_node_path2.join)(TEMP_DIR, `caddy${import_node_process3.default.platform === "win32" ? ".exe" : ""}`);
|
|
159
158
|
var caddyFilePath = (0, import_node_path2.join)(TEMP_DIR, "CADDYFILE");
|
|
160
159
|
var supportList = [
|
|
@@ -328,6 +327,10 @@ async function download() {
|
|
|
328
327
|
if (await testCaddy())
|
|
329
328
|
return caddyPath;
|
|
330
329
|
return new Promise((resolve, reject) => {
|
|
330
|
+
if (!(0, import_node_fs2.existsSync)(TEMP_DIR)) {
|
|
331
|
+
(0, import_node_fs2.mkdirSync)(TEMP_DIR, { recursive: true });
|
|
332
|
+
(0, import_node_fs2.chmodSync)(TEMP_DIR, 511);
|
|
333
|
+
}
|
|
331
334
|
const file = (0, import_node_fs2.createWriteStream)(caddyPath);
|
|
332
335
|
let _platform = (0, import_node_os.platform)().toString();
|
|
333
336
|
_platform === "win32" && (_platform = "windows");
|
|
@@ -342,6 +345,9 @@ async function download() {
|
|
|
342
345
|
const httpsProxy = import_node_process4.default.env.HTTPS_PROXY || import_node_process4.default.env.https_proxy;
|
|
343
346
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
344
347
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
348
|
+
const chmodCaddyOnce = once(() => {
|
|
349
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
350
|
+
});
|
|
345
351
|
import_got_cjs.got.stream(dowmloadLink, {
|
|
346
352
|
agent: {
|
|
347
353
|
http: httpAgent,
|
|
@@ -349,11 +355,12 @@ async function download() {
|
|
|
349
355
|
}
|
|
350
356
|
}).on("downloadProgress", (progress) => {
|
|
351
357
|
logProgress(progress.percent);
|
|
358
|
+
chmodCaddyOnce();
|
|
352
359
|
}).pipe(file).on("finish", () => {
|
|
353
360
|
logProgressOver();
|
|
354
361
|
if (import_node_process4.default.platform === "win32")
|
|
355
362
|
return resolve(caddyPath);
|
|
356
|
-
(0, import_node_fs2.chmodSync)(caddyPath,
|
|
363
|
+
(0, import_node_fs2.chmodSync)(caddyPath, 511);
|
|
357
364
|
resolve(caddyPath);
|
|
358
365
|
}).on("error", (err) => {
|
|
359
366
|
reject(err);
|
|
@@ -436,6 +443,19 @@ var CaddyInstant = class {
|
|
|
436
443
|
});
|
|
437
444
|
const originalExit = import_node_process4.default.exit.bind(import_node_process4.default);
|
|
438
445
|
import_node_process4.default.exit = async (code) => {
|
|
446
|
+
const port = Number(source.split(":")[1]);
|
|
447
|
+
if (!Number.isNaN(port) && await tryPort(port))
|
|
448
|
+
await (0, import_kill_port.default)(port, "tcp");
|
|
449
|
+
const pwd2 = import_node_process4.default.cwd();
|
|
450
|
+
const viteCacheDir = `${pwd2}/node_modules/.vite`;
|
|
451
|
+
if ((0, import_node_fs2.existsSync)(viteCacheDir))
|
|
452
|
+
chmodRecursive(viteCacheDir, 511);
|
|
453
|
+
const nuxtCacheDir = `${pwd2}/.nuxt`;
|
|
454
|
+
if ((0, import_node_fs2.existsSync)(nuxtCacheDir))
|
|
455
|
+
await chmodRecursive(nuxtCacheDir, 511);
|
|
456
|
+
const webpackCacheDir = `${pwd2}/node_modules/.cache`;
|
|
457
|
+
if ((0, import_node_fs2.existsSync)(webpackCacheDir))
|
|
458
|
+
chmodRecursive(webpackCacheDir, 511);
|
|
439
459
|
if (!restore || this.stoped)
|
|
440
460
|
return originalExit(code);
|
|
441
461
|
try {
|
|
@@ -477,27 +497,17 @@ var caddy;
|
|
|
477
497
|
var pwd = import_node_process5.default.cwd();
|
|
478
498
|
var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
|
|
479
499
|
_printUrls == null ? void 0 : _printUrls();
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
base
|
|
492
|
-
}, options)).then(() => {
|
|
493
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
494
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
495
|
-
}).catch((e) => {
|
|
496
|
-
throw e;
|
|
497
|
-
});
|
|
498
|
-
} catch (e) {
|
|
499
|
-
consola.error(e);
|
|
500
|
-
}
|
|
500
|
+
if (caddy)
|
|
501
|
+
return;
|
|
502
|
+
caddy = new CaddyInstant();
|
|
503
|
+
caddy.run(source, target, __spreadValues({
|
|
504
|
+
base
|
|
505
|
+
}, options)).then(() => {
|
|
506
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
507
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
508
|
+
}).catch((e) => {
|
|
509
|
+
throw e;
|
|
510
|
+
});
|
|
501
511
|
});
|
|
502
512
|
var unpluginFactory = (options) => ({
|
|
503
513
|
name: "unplugin-https-reverse-proxy",
|
|
@@ -508,12 +518,12 @@ var unpluginFactory = (options) => ({
|
|
|
508
518
|
},
|
|
509
519
|
configureServer(server) {
|
|
510
520
|
var _a;
|
|
521
|
+
if (config.command !== "serve")
|
|
522
|
+
return;
|
|
511
523
|
if (!isAdmin()) {
|
|
512
524
|
consola.warn("please run as administrator");
|
|
513
525
|
return;
|
|
514
526
|
}
|
|
515
|
-
if (config.command === "build")
|
|
516
|
-
return;
|
|
517
527
|
const {
|
|
518
528
|
enable = true,
|
|
519
529
|
target = ""
|
|
@@ -537,12 +547,12 @@ var unpluginFactory = (options) => ({
|
|
|
537
547
|
},
|
|
538
548
|
webpack(compiler) {
|
|
539
549
|
var _a;
|
|
550
|
+
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
551
|
+
return;
|
|
540
552
|
if (!isAdmin()) {
|
|
541
553
|
consola.warn("please run as administrator");
|
|
542
554
|
return;
|
|
543
555
|
}
|
|
544
|
-
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
545
|
-
return;
|
|
546
556
|
const {
|
|
547
557
|
enable = true,
|
|
548
558
|
target = ""
|
|
@@ -553,39 +563,32 @@ var unpluginFactory = (options) => ({
|
|
|
553
563
|
consola.fail("please provide target");
|
|
554
564
|
return;
|
|
555
565
|
}
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
if (_close) {
|
|
569
|
-
compiler.close = async (callback) => {
|
|
570
|
-
import_node_process5.default.on("exit", () => {
|
|
571
|
-
_close && _close(callback);
|
|
572
|
-
});
|
|
573
|
-
};
|
|
574
|
-
} else {
|
|
575
|
-
options.https = false;
|
|
576
|
-
}
|
|
577
|
-
caddy = new CaddyInstant();
|
|
578
|
-
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
579
|
-
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
580
|
-
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
581
|
-
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
566
|
+
const devServer = __spreadValues(__spreadValues({
|
|
567
|
+
host: "localhost",
|
|
568
|
+
port: 8080
|
|
569
|
+
}, compiler.options.devServer), import_node_process5.default.VUE_CLI_SERVICE.projectOptions.devServer);
|
|
570
|
+
const source = `${devServer.host}:${devServer.port}`;
|
|
571
|
+
if (caddy)
|
|
572
|
+
return;
|
|
573
|
+
const _close = (_a = compiler.close) == null ? void 0 : _a.bind(compiler);
|
|
574
|
+
if (_close) {
|
|
575
|
+
compiler.close = async (callback) => {
|
|
576
|
+
import_node_process5.default.on("exit", () => {
|
|
577
|
+
_close && _close(callback);
|
|
582
578
|
});
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
} catch (e) {
|
|
587
|
-
consola.error(e);
|
|
579
|
+
};
|
|
580
|
+
} else {
|
|
581
|
+
options.https = false;
|
|
588
582
|
}
|
|
583
|
+
caddy = new CaddyInstant();
|
|
584
|
+
caddy.run(source, target, __spreadValues({}, options)).then(() => {
|
|
585
|
+
const colorUrl = (url) => import_picocolors.default.green(url.replace(/:(\d+)\//, (_, port) => `:${import_picocolors.default.bold(port)}/`));
|
|
586
|
+
compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
|
|
587
|
+
consola.success(` ${import_picocolors.default.green("\u279C")} ${import_picocolors.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
588
|
+
});
|
|
589
|
+
}).catch((e) => {
|
|
590
|
+
throw e;
|
|
591
|
+
});
|
|
589
592
|
}
|
|
590
593
|
});
|
|
591
594
|
var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
|