unplugin-https-reverse-proxy 1.0.0-beta.9 → 2.0.0

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.
@@ -1,44 +1,46 @@
1
1
  import {
2
- __spreadValues,
3
2
  chmodRecursive,
4
3
  consola,
4
+ generateQrcode,
5
+ getIpv4List,
5
6
  isAdmin,
6
7
  once
7
- } from "./chunk-RUJE3YFB.js";
8
+ } from "./chunk-2P7SUCQ3.js";
8
9
 
9
10
  // src/index.ts
10
- import process4 from "process";
11
- import { createUnplugin } from "unplugin";
11
+ import process4 from "node:process";
12
+ import { Table } from "console-table-printer";
12
13
  import c from "picocolors";
14
+ import { createUnplugin } from "unplugin";
13
15
 
14
16
  // src/caddy/index.ts
15
- import { platform } from "os";
16
- import process3 from "process";
17
- import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync } from "fs";
18
- import { spawn } from "child_process";
17
+ import { spawn } from "node:child_process";
18
+ import { chmodSync as chmodSync2, createWriteStream, existsSync, mkdirSync, unlinkSync, writeFileSync } from "node:fs";
19
+ import { readFile, unlink, writeFile } from "node:fs/promises";
20
+ import { platform } from "node:os";
21
+ import { join as join2 } from "node:path";
22
+ import process3 from "node:process";
19
23
  import { got } from "got-cjs";
20
24
  import { HttpProxyAgent } from "http-proxy-agent";
21
25
  import { HttpsProxyAgent } from "https-proxy-agent";
22
- import kill from "kill-port";
26
+ import * as lockfile from "proper-lockfile";
23
27
 
24
28
  // src/host/index.ts
25
- import process from "process";
26
- import { exec } from "child_process";
27
- import { chmodSync } from "fs";
28
- import _Hosts from "hosts-so-easy";
29
- var Hosts = _Hosts.default || _Hosts;
30
- var hostInstance = new Hosts({
31
- debounceTime: 50,
32
- hostsFile: getPathOfSystemHostsPath()
33
- });
29
+ import { exec } from "node:child_process";
30
+ import { chmodSync } from "node:fs";
31
+ import process from "node:process";
32
+ import { promisify } from "node:util";
33
+ import hostile from "hostile";
34
+ var _setHost = promisify(hostile.set);
35
+ var _removeHost = promisify(hostile.remove);
34
36
  function getPathOfSystemHostsPath() {
35
37
  return process.platform === "win32" ? `${process.env.windir || "C:\\WINDOWS"}\\system32\\drivers\\etc\\hosts` : "/etc/hosts";
36
38
  }
37
39
  async function syncHost() {
38
- return new Promise((resolve, reject) => {
40
+ return new Promise((resolve, _reject) => {
39
41
  exec(
40
42
  process.platform === "win32" ? "ipconfig /flushdns" : "sudo -E killall -HUP mDNSResponder",
41
- (error, stdout, stderr) => {
43
+ (error, _stdout, _stderr) => {
42
44
  if (error) {
43
45
  consola.error(`exec error: ${error}`);
44
46
  return resolve(false);
@@ -51,27 +53,25 @@ async function syncHost() {
51
53
  async function addHost(ip, host) {
52
54
  if (process.platform !== "win32")
53
55
  chmodSync(getPathOfSystemHostsPath(), 511);
54
- hostInstance.add("127.0.0.1", "localhost");
55
- hostInstance.add(ip, host);
56
+ await _setHost("127.0.0.1", "localhost");
57
+ await _setHost(ip, host);
56
58
  if (ip === "localhost")
57
- hostInstance.add("127.0.0.1", host);
58
- await hostInstance.updateFinish();
59
+ await _setHost("127.0.0.1", host);
59
60
  return await syncHost();
60
61
  }
61
62
  async function removeHost(ip, host) {
62
63
  if (process.platform !== "win32")
63
64
  chmodSync(getPathOfSystemHostsPath(), 511);
64
- hostInstance.remove(ip, host);
65
+ await _removeHost(ip, host);
65
66
  if (ip === "localhost")
66
- hostInstance.remove("127.0.0.1", host);
67
- await hostInstance.updateFinish();
67
+ await _removeHost("127.0.0.1", host);
68
68
  return await syncHost();
69
69
  }
70
70
 
71
71
  // src/caddy/constants.ts
72
- import { join } from "path";
73
- import os from "os";
74
- import process2 from "process";
72
+ import os from "node:os";
73
+ import { join } from "node:path";
74
+ import process2 from "node:process";
75
75
  import dotenvFlow from "dotenv-flow";
76
76
  dotenvFlow.config({
77
77
  silent: true
@@ -84,6 +84,7 @@ function resolvePath(path) {
84
84
  var TEMP_DIR = resolvePath(process2.env.UHRP_CADDY_PATH || process2.env.TEMP || process2.env.TMPDIR || "/tmp");
85
85
  var caddyPath = join(TEMP_DIR, `caddy${process2.platform === "win32" ? ".exe" : ""}`);
86
86
  var caddyFilePath = join(TEMP_DIR, "CADDYFILE");
87
+ var caddyLockFilePath = join(TEMP_DIR, "caddylock");
87
88
  var supportList = [
88
89
  {
89
90
  platform: "dragonfly",
@@ -196,11 +197,12 @@ var supportList = [
196
197
  ];
197
198
 
198
199
  // src/caddy/utils.ts
199
- import { createServer } from "net";
200
+ import { exec as exec2 } from "node:child_process";
201
+ import { createServer } from "node:net";
200
202
  import ora from "ora";
201
203
  var spinner;
202
204
  function tryPort(port) {
203
- return new Promise((resolve, reject) => {
205
+ return new Promise((resolve, _reject) => {
204
206
  try {
205
207
  const server = createServer().listen(port);
206
208
  server.on("listening", () => {
@@ -212,11 +214,23 @@ function tryPort(port) {
212
214
  resolve(true);
213
215
  server.close();
214
216
  });
215
- } catch (e) {
217
+ } catch {
216
218
  resolve(true);
217
219
  }
218
220
  });
219
221
  }
222
+ async function kill(port) {
223
+ return new Promise((resolve, reject) => {
224
+ exec2(`npx @maxbo/free-port ${port} -s`, (err, stdout, _stderr) => {
225
+ if (err) {
226
+ reject(err);
227
+ } else {
228
+ consola.log(stdout);
229
+ resolve();
230
+ }
231
+ });
232
+ });
233
+ }
220
234
  function getNumber(number) {
221
235
  if (number <= 0)
222
236
  return "0%";
@@ -267,7 +281,7 @@ async function download() {
267
281
  const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
268
282
  if (!support)
269
283
  return reject(new Error("not support"));
270
- const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}`;
284
+ const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
271
285
  existsSync(caddyPath) && unlinkSync(caddyPath);
272
286
  const httpProxy = process3.env.HTTP_PROXY || process3.env.http_proxy;
273
287
  const httpsProxy = process3.env.HTTPS_PROXY || process3.env.https_proxy;
@@ -316,9 +330,61 @@ var CaddyInstant = class {
316
330
  constructor() {
317
331
  this.inited = false;
318
332
  this.stoped = false;
319
- testCaddy().then(() => {
333
+ /** has locked */
334
+ this.locked = false;
335
+ testCaddy().then(async () => {
336
+ await this.getCaddyfile();
320
337
  this.inited = true;
321
338
  });
339
+ this.locked = this.checkLock();
340
+ }
341
+ checkLock() {
342
+ if (!existsSync(caddyLockFilePath))
343
+ writeFileSync(caddyLockFilePath, "");
344
+ return lockfile.checkSync(caddyLockFilePath);
345
+ }
346
+ async getCaddyfile() {
347
+ if (!existsSync(caddyFilePath))
348
+ await this.initCaddyfile();
349
+ this.caddyfile = await readFile(caddyFilePath, "utf-8");
350
+ return this.caddyfile;
351
+ }
352
+ async initCaddyfile() {
353
+ const contet = `
354
+ {
355
+ debug
356
+ auto_https disable_redirects
357
+ }
358
+
359
+ :7601 {
360
+ root * "${join2(
361
+ process3.platform === "win32" ? `${process3.env.AppData}/Caddy` : `${process3.env.HOME}/Library/Application Support/Caddy`,
362
+ "./pki/authorities/local"
363
+ )}"
364
+ file_server browse
365
+ }
366
+
367
+ # \u6B63\u5411\u4EE3\u7406\u914D\u7F6E
368
+ :7600 {
369
+ bind 0.0.0.0
370
+
371
+ forward_proxy {
372
+ hide_ip
373
+ hide_via
374
+ acl {
375
+ allow all
376
+ }
377
+ }
378
+ }
379
+ `;
380
+ await writeFile(caddyFilePath, contet);
381
+ this.caddyfile = contet;
382
+ }
383
+ async writeCaddyfile() {
384
+ return await writeFile(caddyFilePath, this.caddyfile || "");
385
+ }
386
+ async deleteCaddyfile() {
387
+ return await unlink(caddyFilePath);
322
388
  }
323
389
  async init() {
324
390
  await download();
@@ -327,7 +393,6 @@ var CaddyInstant = class {
327
393
  /**
328
394
  * @param source like `127.0.0.1:8080`
329
395
  * @param target like `test.abc.com`. And if you provide a port ,it will be ignore.
330
- * @returns
331
396
  */
332
397
  async run(source, target, options) {
333
398
  source = source.replace("0.0.0.0", "127.0.0.1");
@@ -337,101 +402,216 @@ var CaddyInstant = class {
337
402
  showCaddyLog = false,
338
403
  https = false
339
404
  } = options || {};
405
+ this._source = source;
406
+ this._target = target;
340
407
  if (!this.inited)
341
408
  await this.init();
342
- if (https && await tryPort(443))
343
- await kill(443, "tcp");
344
- if ((process3.platform === "win32" || !https) && await tryPort(80))
345
- await kill(80, "tcp");
346
409
  if (!await addHost(source.split(":")[0], target.split(":")[0]))
347
410
  throw new Error("update host failed");
348
411
  consola.success("update host success\n");
412
+ await this.getCaddyfile();
413
+ if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
414
+ this.caddyfile = `${this.caddyfile}
415
+ ${target.split(":")[0]}${https ? "" : ":80"} {
416
+ ${https ? "tls internal" : ""}
417
+ reverse_proxy http://${source} {
418
+ health_uri ${base}
419
+ health_interval 2s
420
+ health_timeout 5s
421
+ fail_duration 2s
422
+ unhealthy_status 502 503 504 404
423
+ lb_try_duration 3s
424
+ lb_try_interval 300ms
425
+ health_headers {
426
+ Accept text/html
427
+ Accept-Encoding gzip, deflate, br
428
+ User-Agent Caddy-Health-Check
429
+ }
430
+
431
+ @error status 502 503 504 404
432
+ handle_response @error {
433
+ respond * 503 {
434
+ body "Service Unavailable"
435
+ close
436
+ }
437
+ }
438
+ }
439
+ }
440
+ `;
441
+ await this.writeCaddyfile();
442
+ }
443
+ if (!existsSync(caddyLockFilePath))
444
+ writeFileSync(caddyLockFilePath, "");
445
+ if (!this.locked) {
446
+ if (await tryPort(443))
447
+ await kill(443);
448
+ if ((process3.platform === "win32" || !https) && await tryPort(80))
449
+ await kill(80);
450
+ }
349
451
  return new Promise((resolve, reject) => {
350
- const child = process3.platform !== "win32" ? spawn("sudo", ["-E", caddyPath, "reverse-proxy", "--from", `${target.split(":")[0]}${https ? "" : ":80"}`, "--to", `${source}`, "--internal-certs", "--insecure", "--disable-redirects"]) : spawn(caddyPath, ["reverse-proxy", "--from", `${target.split(":")[0]}`, "--to", `${source}`, "--internal-certs"]);
351
- child.on("error", (err) => {
352
- return reject(err);
353
- });
354
- process3.on("SIGINT", async () => {
355
- if (!restore || this.stoped)
356
- return;
357
- try {
358
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
359
- consola.success("restore host success\n");
360
- else
361
- consola.fail("restore host failed\n");
362
- } catch (e) {
363
- consola.error(e);
364
- consola.fail("restore host failed\n");
365
- } finally {
366
- this.stoped = true;
367
- process3.nextTick(() => {
368
- process3.exit();
369
- });
370
- }
371
- });
372
- const originalExit = process3.exit.bind(process3);
373
- process3.exit = async (code) => {
374
- const port = Number(source.split(":")[1]);
375
- if (!Number.isNaN(port) && await tryPort(port))
376
- await kill(port, "tcp");
377
- const pwd = process3.cwd();
378
- const viteCacheDir = `${pwd}/node_modules/.vite`;
379
- if (existsSync(viteCacheDir))
380
- chmodRecursive(viteCacheDir, 511);
381
- const nuxtCacheDir = `${pwd}/.nuxt`;
382
- if (existsSync(nuxtCacheDir))
383
- await chmodRecursive(nuxtCacheDir, 511);
384
- const webpackCacheDir = `${pwd}/node_modules/.cache`;
385
- if (existsSync(webpackCacheDir))
386
- chmodRecursive(webpackCacheDir, 511);
387
- if (!restore || this.stoped)
388
- return originalExit(code);
389
- try {
390
- if (await removeHost(source.split(":")[0], target.split(":")[0]))
391
- consola.success("restore host success\n");
392
- else
393
- consola.fail("restore host failed\n");
394
- } catch (e) {
395
- consola.error(e);
396
- consola.fail("restore host failed\n");
397
- } finally {
398
- this.stoped = true;
399
- process3.nextTick(() => {
400
- originalExit(code);
401
- });
402
- }
452
+ var _a, _b;
453
+ const setupCleanup = () => {
454
+ process3.on("SIGINT", async () => {
455
+ if (this.stoped)
456
+ return;
457
+ process3.stdin.resume();
458
+ try {
459
+ await this.baseCleanup(restore);
460
+ } finally {
461
+ this.stoped = true;
462
+ process3.nextTick(() => {
463
+ process3.exit();
464
+ });
465
+ }
466
+ });
467
+ const originalExit = process3.exit.bind(process3);
468
+ process3.exit = async (code) => {
469
+ const port = Number(source.split(":")[1]);
470
+ if (!Number.isNaN(port) && await tryPort(port))
471
+ await kill(port);
472
+ const pwd = process3.cwd();
473
+ const viteCacheDir = `${pwd}/node_modules/.vite`;
474
+ if (existsSync(viteCacheDir))
475
+ await chmodRecursive(viteCacheDir, 511).catch(() => {
476
+ });
477
+ const nuxtCacheDir = `${pwd}/.nuxt`;
478
+ if (existsSync(nuxtCacheDir))
479
+ await chmodRecursive(nuxtCacheDir, 511).catch(() => {
480
+ });
481
+ const webpackCacheDir = `${pwd}/node_modules/.cache`;
482
+ if (existsSync(webpackCacheDir))
483
+ await chmodRecursive(webpackCacheDir, 511).catch(() => {
484
+ });
485
+ if (this.stoped)
486
+ return originalExit(code);
487
+ process3.stdin.resume();
488
+ try {
489
+ await this.baseCleanup();
490
+ } finally {
491
+ this.stoped = true;
492
+ process3.nextTick(() => {
493
+ originalExit(code);
494
+ });
495
+ }
496
+ };
403
497
  };
404
- child.stderr.on("data", (data) => {
405
- const lines = data.toString().split("\n").map((line) => line.trim());
406
- for (const line of lines) {
407
- showCaddyLog && line && console.info(line);
408
- if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
409
- consola.error(line);
410
- return reject(line);
498
+ if (!this.locked) {
499
+ this._caddyChild = process3.platform !== "win32" ? spawn("sudo", ["-E", caddyPath, "run", "--config", caddyFilePath, "--watch"]) : spawn(caddyPath, ["run", "--config", caddyFilePath, "--watch"]);
500
+ lockfile.lockSync(caddyLockFilePath);
501
+ this._caddyChild.on("error", (err) => {
502
+ return reject(err);
503
+ });
504
+ (_a = this._caddyChild.stderr) == null ? void 0 : _a.on("data", async (data) => {
505
+ const lines = data.toString().split("\n").map((line) => line.trim());
506
+ for (const line of lines) {
507
+ showCaddyLog && line && console.info(line);
508
+ if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
509
+ if (line.includes("parsing caddyfile tokens")) {
510
+ consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
511
+
512
+ ${line}
513
+ `);
514
+ await this.baseCleanup();
515
+ process3.exit();
516
+ } else {
517
+ consola.error(`${line}
518
+ `);
519
+ return reject(line);
520
+ }
521
+ }
522
+ if (line.includes("config file changed"))
523
+ consola.success("Detect added a new reverse proxy config, restarted.\n");
524
+ if (line.includes("caddy proxying") || line.includes("serving initial"))
525
+ return resolve();
411
526
  }
412
- }
413
- });
414
- child.stdout.on("data", (_data) => {
415
- consola.info(_data.toString());
416
- resolve();
417
- });
527
+ });
528
+ (_b = this._caddyChild.stdout) == null ? void 0 : _b.on("data", (_data) => {
529
+ consola.info(_data.toString());
530
+ resolve();
531
+ });
532
+ setupCleanup();
533
+ } else {
534
+ consola.info("Caddy is running in another process.");
535
+ setupCleanup();
536
+ return resolve();
537
+ }
418
538
  });
419
539
  }
540
+ async baseCleanup(restore = true) {
541
+ var _a;
542
+ try {
543
+ if (restore && this._source && this._target) {
544
+ if (await removeHost(this._source.split(":")[0], this._target.split(":")[0]))
545
+ consola.success("Restore host success.\n");
546
+ else
547
+ consola.fail("Restore host failed.\n");
548
+ }
549
+ } catch (e) {
550
+ consola.error(e);
551
+ consola.fail("Restore host failed.\n");
552
+ }
553
+ if (!this.locked && !this.stoped) {
554
+ (_a = this._caddyChild) == null ? void 0 : _a.kill();
555
+ try {
556
+ await lockfile.unlock(caddyLockFilePath).catch(() => {
557
+ });
558
+ await unlink(caddyFilePath).catch(() => {
559
+ });
560
+ await unlink(caddyLockFilePath).catch(() => {
561
+ });
562
+ } catch (e) {
563
+ consola.error(e);
564
+ }
565
+ }
566
+ }
420
567
  };
421
568
 
422
569
  // src/index.ts
423
570
  var config;
424
571
  var caddy;
425
572
  var cwd = process4.cwd();
573
+ function colorUrl(url) {
574
+ return c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
575
+ }
576
+ async function printForwardProxy() {
577
+ const ipv4List = getIpv4List();
578
+ if (ipv4List.length) {
579
+ const ips = ipv4List.map((ip) => c.cyan(ip)).join(", ");
580
+ consola.info(`${c.bold("Mobile device proxy access")}:
581
+ `);
582
+ consola.info("1. Install certificate: scan the QR code and download the `root.crt` file,");
583
+ consola.info(" then install it on your mobile device");
584
+ const ipTable = await Promise.all(
585
+ ipv4List.map(async (ip) => ({
586
+ target: `http://${ip}:7601`,
587
+ certificate: await generateQrcode(`http://${ip}:7601`)
588
+ }))
589
+ );
590
+ const table = new Table({
591
+ columns: [
592
+ { name: "target", alignment: "left" },
593
+ { name: "certificate", alignment: "center", minLen: 28 }
594
+ ]
595
+ });
596
+ ipTable.forEach((ip) => {
597
+ table.addRow(ip);
598
+ });
599
+ table.printTable();
600
+ consola.info(`2. Set proxy on mobile device (Available IPs: ${ips}):${c.bold(7600)}
601
+
602
+ `);
603
+ }
604
+ }
426
605
  var vitePrintUrls = once((options, source, target, base = "/", _printUrls) => {
427
606
  _printUrls == null ? void 0 : _printUrls();
428
607
  if (caddy)
429
608
  return;
430
609
  caddy = new CaddyInstant();
431
- caddy.run(source, target, __spreadValues({
432
- base
433
- }, options)).then(() => {
434
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
610
+ caddy.run(source, target, {
611
+ base,
612
+ ...options
613
+ }).then(async () => {
614
+ await printForwardProxy();
435
615
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
436
616
  }).catch((e) => {
437
617
  throw e;
@@ -448,16 +628,16 @@ var unpluginFactory = (options) => ({
448
628
  var _a;
449
629
  if (config.command !== "serve")
450
630
  return;
451
- if (!isAdmin()) {
452
- consola.warn("please run as administrator");
453
- return;
454
- }
455
631
  const {
456
632
  enable = true,
457
633
  target = ""
458
634
  } = options;
459
635
  if (!enable)
460
636
  return;
637
+ if (!isAdmin()) {
638
+ consola.warn("please run as administrator");
639
+ return;
640
+ }
461
641
  if (!target) {
462
642
  consola.fail("please provide target");
463
643
  return;
@@ -477,24 +657,27 @@ var unpluginFactory = (options) => ({
477
657
  var _a, _b;
478
658
  if (process4.env.NODE_ENV !== "development")
479
659
  return;
480
- if (!isAdmin()) {
481
- consola.warn("please run as administrator");
482
- return;
483
- }
484
660
  const {
485
661
  enable = true,
486
662
  target = ""
487
663
  } = options;
488
664
  if (!enable)
489
665
  return;
666
+ if (!isAdmin()) {
667
+ consola.warn("please run as administrator");
668
+ return;
669
+ }
490
670
  if (!target) {
491
671
  consola.fail("please provide target");
492
672
  return;
493
673
  }
494
- const devServer = __spreadValues(__spreadValues({
674
+ const devServer = {
495
675
  host: "localhost",
496
- port: 8080
497
- }, compiler.options.devServer), (_a = process4.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer);
676
+ port: 8080,
677
+ ...compiler.options.devServer,
678
+ // @ts-expect-error vuecli
679
+ ...(_a = process4.VUE_CLI_SERVICE) == null ? void 0 : _a.projectOptions.devServer
680
+ };
498
681
  const source = `${devServer.host}:${devServer.port}`;
499
682
  if (caddy)
500
683
  return;
@@ -509,9 +692,11 @@ var unpluginFactory = (options) => ({
509
692
  options.https = false;
510
693
  }
511
694
  caddy = new CaddyInstant();
512
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
513
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
514
- compiler.hooks.done.tap("unplugin-https-reverse-proxy", () => {
695
+ caddy.run(source, target, {
696
+ ...options
697
+ }).then(() => {
698
+ compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
699
+ await printForwardProxy();
515
700
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
516
701
  });
517
702
  }).catch((e) => {
@@ -522,32 +707,36 @@ var unpluginFactory = (options) => ({
522
707
  var _a, _b, _c;
523
708
  if (process4.env.NODE_ENV !== "development")
524
709
  return;
525
- if (!isAdmin()) {
526
- consola.warn("please run as administrator");
527
- return;
528
- }
529
710
  const {
530
711
  enable = true,
531
712
  target = ""
532
713
  } = options;
533
714
  if (!enable)
534
715
  return;
716
+ if (!isAdmin()) {
717
+ consola.warn("please run as administrator");
718
+ return;
719
+ }
535
720
  if (!target) {
536
721
  consola.fail("please provide target");
537
722
  return;
538
723
  }
539
- const devServer = __spreadValues(__spreadValues({
724
+ const devServer = {
540
725
  host: "localhost",
541
- port: 8080
542
- }, compiler.options.devServer), (_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
543
- cwd
544
- }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server);
726
+ port: 8080,
727
+ ...compiler.options.devServer,
728
+ ...(_c = (_b = await ((_a = await import("@rsbuild/core")) == null ? void 0 : _a.loadConfig({
729
+ cwd
730
+ }))) == null ? void 0 : _b.content) == null ? void 0 : _c.server
731
+ };
545
732
  const source = `${devServer.host}:${devServer.port}`;
546
733
  if (caddy)
547
734
  return;
548
735
  caddy = new CaddyInstant();
549
- caddy.run(source, target, __spreadValues({}, options)).then(() => {
550
- const colorUrl = (url) => c.green(url.replace(/:(\d+)\//, (_, port) => `:${c.bold(port)}/`));
736
+ caddy.run(source, target, {
737
+ ...options
738
+ }).then(async () => {
739
+ await printForwardProxy();
551
740
  consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
552
741
  }).catch((e) => {
553
742
  throw e;