unplugin-https-reverse-proxy 2.0.3-beta.2 → 4.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.
package/dist/rollup.cjs CHANGED
@@ -13437,11 +13437,11 @@ var Liquid = class _Liquid {
13437
13437
  // src/caddy/caddyfile.ts
13438
13438
  var ProxyType = type({
13439
13439
  target: "string",
13440
- port_suffix: "string",
13440
+ portSuffix: "string",
13441
13441
  tls: "string",
13442
13442
  source: "string",
13443
13443
  base: "string",
13444
- health_check: "boolean"
13444
+ healthCheck: "boolean"
13445
13445
  });
13446
13446
  var CaddyContext = type({
13447
13447
  caddy_root: "string",
@@ -13476,33 +13476,63 @@ var caddyTemplate = `{
13476
13476
  }
13477
13477
  }
13478
13478
 
13479
- {% for p in proxies %}
13480
- {{ p.target }}{{ p.port_suffix }} {
13481
- {{ p.tls }}
13482
- reverse_proxy http://{{ p.source }} {% if p.health_check %} {
13483
- health_uri {{ p.base }}
13484
- health_interval 2s
13485
- health_timeout 5s
13486
- fail_duration 2s
13487
- unhealthy_status 502 503 504 404
13488
- lb_try_duration 3s
13489
- lb_try_interval 300ms
13479
+ {% for host in hosts %}
13480
+ {{ host.host }}{{ host.portSuffix }} {
13481
+ {{ host.tls }}
13490
13482
 
13491
- @error status 502 503 504 404
13492
- handle_response @error {
13493
- respond * 503 {
13494
- body "Service Unavailable"
13495
- close
13483
+ {% for route in host.routes %}
13484
+ handle {{ route.base }}* {
13485
+ reverse_proxy http://{{ route.source }} {% if route.healthCheck %} {
13486
+ health_uri {{ route.base }}
13487
+ health_interval 2s
13488
+ health_timeout 5s
13489
+ health_headers {
13490
+ User-Agent {http.request.header.User-Agent}
13491
+ Accept text/html,application/json,*/*
13492
+ }
13493
+ fail_duration 2s
13494
+ unhealthy_status 502 503 504 404
13495
+ lb_try_duration 3s
13496
+ lb_try_interval 300ms
13497
+
13498
+ @error status 502 503 504 404
13499
+ handle_response @error {
13500
+ respond * 503 {
13501
+ body "Service Unavailable"
13502
+ close
13503
+ }
13496
13504
  }
13497
13505
  }
13506
+ {% endif %}
13498
13507
  }
13499
- {% endif %}
13508
+ {% endfor %}
13500
13509
  }
13501
13510
  {% endfor %}
13502
13511
  `;
13503
13512
  var liquid = new Liquid();
13504
13513
  async function genCaddyfile(ctx) {
13505
- return await liquid.parseAndRender(caddyTemplate, ctx);
13514
+ const hostsMap = /* @__PURE__ */ new Map();
13515
+ for (const proxy of ctx.proxies) {
13516
+ const key = `${proxy.target}${proxy.portSuffix}`;
13517
+ if (!hostsMap.has(key)) {
13518
+ hostsMap.set(key, {
13519
+ host: proxy.target,
13520
+ portSuffix: proxy.portSuffix,
13521
+ tls: proxy.tls,
13522
+ routes: []
13523
+ });
13524
+ }
13525
+ let base = proxy.base || "/";
13526
+ if (!base.startsWith("/"))
13527
+ base = `/${base}`;
13528
+ if (base !== "/" && !base.endsWith("/"))
13529
+ base = `${base}/`;
13530
+ hostsMap.get(key).routes.push({ ...proxy, base });
13531
+ }
13532
+ for (const host of hostsMap.values())
13533
+ host.routes.sort((a, b) => b.base.length - a.base.length);
13534
+ const hosts = Array.from(hostsMap.values());
13535
+ return await liquid.parseAndRender(caddyTemplate, { ...ctx, hosts });
13506
13536
  }
13507
13537
 
13508
13538
  // src/caddy/config.ts
@@ -13641,7 +13671,7 @@ var supportList = [
13641
13671
  // src/caddy/config.ts
13642
13672
  function useCaddyConfig() {
13643
13673
  const configContentRef = signal("{}");
13644
- const configJsonRef2 = computed(() => {
13674
+ const configJsonRef = computed(() => {
13645
13675
  try {
13646
13676
  return JSON.parse(configContentRef());
13647
13677
  } catch {
@@ -13664,26 +13694,31 @@ function useCaddyConfig() {
13664
13694
  const watchCaddyConfig = (0, import_node_fs2.watch)(caddyConfigPath, () => {
13665
13695
  setConfigContent();
13666
13696
  });
13667
- function writeCaddyConfig2(_proxies) {
13668
- const proxies = configJsonRef2() || {};
13697
+ function writeCaddyConfig(_proxies) {
13698
+ const proxies = configJsonRef() || {};
13669
13699
  _proxies.forEach((p) => {
13670
- const index = `${p.target}${p.port_suffix}`;
13671
- proxies[index] = p;
13700
+ let base = p.base || "/";
13701
+ if (!base.startsWith("/"))
13702
+ base = `/${base}`;
13703
+ if (base !== "/" && !base.endsWith("/"))
13704
+ base = `${base}/`;
13705
+ const index = `${p.target}${p.portSuffix}${base}`;
13706
+ proxies[index] = { ...p, base };
13672
13707
  });
13673
13708
  const content = JSON.stringify(proxies, null, 2);
13674
13709
  configContentRef(content);
13675
13710
  return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
13676
13711
  }
13677
- async function cleanUp2() {
13712
+ async function cleanUp() {
13678
13713
  await (0, import_promises2.unlink)(caddyConfigPath).catch(() => {
13679
13714
  });
13680
13715
  configContentRef("{}");
13681
13716
  watchCaddyConfig.close();
13682
13717
  }
13683
13718
  return {
13684
- configJsonRef: configJsonRef2,
13685
- writeCaddyConfig: writeCaddyConfig2,
13686
- cleanUp: cleanUp2
13719
+ configJsonRef,
13720
+ writeCaddyConfig,
13721
+ cleanUp
13687
13722
  };
13688
13723
  }
13689
13724
 
@@ -13817,7 +13852,13 @@ function testCaddy() {
13817
13852
  });
13818
13853
  });
13819
13854
  }
13820
- var { cleanUp, configJsonRef, writeCaddyConfig } = useCaddyConfig();
13855
+ var caddyConfig;
13856
+ function getCaddyConfig() {
13857
+ if (!caddyConfig) {
13858
+ caddyConfig = useCaddyConfig();
13859
+ }
13860
+ return caddyConfig;
13861
+ }
13821
13862
  var CaddyInstant = class {
13822
13863
  constructor() {
13823
13864
  this.inited = false;
@@ -13870,7 +13911,7 @@ var CaddyInstant = class {
13870
13911
  base = "/",
13871
13912
  showCaddyLog = false,
13872
13913
  https = false,
13873
- health_check = true
13914
+ healthCheck = true
13874
13915
  } = options || {};
13875
13916
  this._source = source;
13876
13917
  this._target = target;
@@ -13880,28 +13921,37 @@ var CaddyInstant = class {
13880
13921
  throw new Error("update host failed");
13881
13922
  consola.success("update host success\n");
13882
13923
  const targetHost = target.split(":")[0];
13924
+ const normalizeBase = (b) => {
13925
+ let out = b || "/";
13926
+ if (!out.startsWith("/"))
13927
+ out = `/${out}`;
13928
+ if (out !== "/" && !out.endsWith("/"))
13929
+ out = `${out}/`;
13930
+ return out;
13931
+ };
13932
+ const baseNormalized = normalizeBase(base);
13883
13933
  const proxies = [
13884
13934
  {
13885
13935
  target: targetHost,
13886
- port_suffix: https ? "" : ":80",
13936
+ portSuffix: https ? "" : ":80",
13887
13937
  tls: https ? "tls internal" : "",
13888
13938
  source,
13889
- base,
13890
- health_check
13939
+ base: baseNormalized,
13940
+ healthCheck
13891
13941
  }
13892
13942
  ];
13943
+ const { writeCaddyConfig } = getCaddyConfig();
13893
13944
  writeCaddyConfig(proxies);
13894
13945
  this._stopEffects.push(
13895
13946
  effect(async () => {
13947
+ const { configJsonRef } = getCaddyConfig();
13896
13948
  const proxies2 = Object.values(configJsonRef() || {});
13897
- if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
13898
- const ctx = validateTemplateContext({
13899
- caddy_root: this.caddyRoot,
13900
- proxies: proxies2
13901
- });
13902
- this.caddyfile = await genCaddyfile(ctx);
13903
- await this.writeCaddyfile();
13904
- }
13949
+ const ctx = validateTemplateContext({
13950
+ caddy_root: this.caddyRoot,
13951
+ proxies: proxies2
13952
+ });
13953
+ this.caddyfile = await genCaddyfile(ctx);
13954
+ await this.writeCaddyfile();
13905
13955
  })
13906
13956
  );
13907
13957
  if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
@@ -14027,7 +14077,9 @@ ${line}
14027
14077
  });
14028
14078
  await (0, import_promises3.unlink)(caddyLockFilePath).catch(() => {
14029
14079
  });
14030
- await cleanUp();
14080
+ if (caddyConfig) {
14081
+ await caddyConfig.cleanUp();
14082
+ }
14031
14083
  } catch (e) {
14032
14084
  consola.error(e);
14033
14085
  }
@@ -14127,7 +14179,7 @@ var unpluginFactory = (options) => ({
14127
14179
  }
14128
14180
  },
14129
14181
  webpack(compiler) {
14130
- var _a4, _b3;
14182
+ var _a4, _b3, _c2;
14131
14183
  if (import_node_process5.default.env.NODE_ENV !== "development")
14132
14184
  return;
14133
14185
  const {
@@ -14158,7 +14210,16 @@ var unpluginFactory = (options) => ({
14158
14210
  const source = `${devServer.host}:${devServer.port}`;
14159
14211
  if (caddy)
14160
14212
  return;
14161
- const _close = (_b3 = compiler.close) == null ? void 0 : _b3.bind(compiler);
14213
+ let base = "/";
14214
+ const publicPath = (_b3 = compiler.options.output) == null ? void 0 : _b3.publicPath;
14215
+ if (typeof publicPath === "string" && publicPath) {
14216
+ base = publicPath;
14217
+ }
14218
+ if (!base.startsWith("/"))
14219
+ base = `/${base}`;
14220
+ if (base !== "/" && !base.endsWith("/"))
14221
+ base = `${base}/`;
14222
+ const _close = (_c2 = compiler.close) == null ? void 0 : _c2.bind(compiler);
14162
14223
  if (_close) {
14163
14224
  compiler.close = async (callback) => {
14164
14225
  import_node_process5.default.on("exit", () => {
@@ -14170,18 +14231,19 @@ var unpluginFactory = (options) => ({
14170
14231
  }
14171
14232
  caddy = new CaddyInstant();
14172
14233
  caddy.run(source, target, {
14234
+ base,
14173
14235
  ...options
14174
14236
  }).then(() => {
14175
14237
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
14176
14238
  await printForwardProxy();
14177
- consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
14239
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
14178
14240
  });
14179
14241
  }).catch((e) => {
14180
14242
  throw e;
14181
14243
  });
14182
14244
  },
14183
14245
  async rspack(compiler) {
14184
- var _a4, _b3, _c2;
14246
+ var _a4, _b3, _c2, _d2;
14185
14247
  if (import_node_process5.default.env.NODE_ENV !== "development")
14186
14248
  return;
14187
14249
  const {
@@ -14214,11 +14276,21 @@ var unpluginFactory = (options) => ({
14214
14276
  if (caddy)
14215
14277
  return;
14216
14278
  caddy = new CaddyInstant();
14279
+ let base = "/";
14280
+ const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
14281
+ if (typeof publicPath === "string" && publicPath) {
14282
+ base = publicPath;
14283
+ }
14284
+ if (!base.startsWith("/"))
14285
+ base = `/${base}`;
14286
+ if (base !== "/" && !base.endsWith("/"))
14287
+ base = `${base}/`;
14217
14288
  caddy.run(source, target, {
14289
+ base,
14218
14290
  ...options
14219
14291
  }).then(async () => {
14220
14292
  await printForwardProxy();
14221
- consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
14293
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
14222
14294
  }).catch((e) => {
14223
14295
  throw e;
14224
14296
  });
package/dist/rollup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-XGTVAT6M.js";
3
+ } from "./chunk-K7HSLE6X.js";
4
4
  import "./chunk-2P7SUCQ3.js";
5
5
 
6
6
  // src/rollup.ts
package/dist/rspack.cjs CHANGED
@@ -13436,11 +13436,11 @@ var Liquid = class _Liquid {
13436
13436
  // src/caddy/caddyfile.ts
13437
13437
  var ProxyType = type({
13438
13438
  target: "string",
13439
- port_suffix: "string",
13439
+ portSuffix: "string",
13440
13440
  tls: "string",
13441
13441
  source: "string",
13442
13442
  base: "string",
13443
- health_check: "boolean"
13443
+ healthCheck: "boolean"
13444
13444
  });
13445
13445
  var CaddyContext = type({
13446
13446
  caddy_root: "string",
@@ -13475,33 +13475,63 @@ var caddyTemplate = `{
13475
13475
  }
13476
13476
  }
13477
13477
 
13478
- {% for p in proxies %}
13479
- {{ p.target }}{{ p.port_suffix }} {
13480
- {{ p.tls }}
13481
- reverse_proxy http://{{ p.source }} {% if p.health_check %} {
13482
- health_uri {{ p.base }}
13483
- health_interval 2s
13484
- health_timeout 5s
13485
- fail_duration 2s
13486
- unhealthy_status 502 503 504 404
13487
- lb_try_duration 3s
13488
- lb_try_interval 300ms
13478
+ {% for host in hosts %}
13479
+ {{ host.host }}{{ host.portSuffix }} {
13480
+ {{ host.tls }}
13489
13481
 
13490
- @error status 502 503 504 404
13491
- handle_response @error {
13492
- respond * 503 {
13493
- body "Service Unavailable"
13494
- close
13482
+ {% for route in host.routes %}
13483
+ handle {{ route.base }}* {
13484
+ reverse_proxy http://{{ route.source }} {% if route.healthCheck %} {
13485
+ health_uri {{ route.base }}
13486
+ health_interval 2s
13487
+ health_timeout 5s
13488
+ health_headers {
13489
+ User-Agent {http.request.header.User-Agent}
13490
+ Accept text/html,application/json,*/*
13491
+ }
13492
+ fail_duration 2s
13493
+ unhealthy_status 502 503 504 404
13494
+ lb_try_duration 3s
13495
+ lb_try_interval 300ms
13496
+
13497
+ @error status 502 503 504 404
13498
+ handle_response @error {
13499
+ respond * 503 {
13500
+ body "Service Unavailable"
13501
+ close
13502
+ }
13495
13503
  }
13496
13504
  }
13505
+ {% endif %}
13497
13506
  }
13498
- {% endif %}
13507
+ {% endfor %}
13499
13508
  }
13500
13509
  {% endfor %}
13501
13510
  `;
13502
13511
  var liquid = new Liquid();
13503
13512
  async function genCaddyfile(ctx) {
13504
- return await liquid.parseAndRender(caddyTemplate, ctx);
13513
+ const hostsMap = /* @__PURE__ */ new Map();
13514
+ for (const proxy of ctx.proxies) {
13515
+ const key = `${proxy.target}${proxy.portSuffix}`;
13516
+ if (!hostsMap.has(key)) {
13517
+ hostsMap.set(key, {
13518
+ host: proxy.target,
13519
+ portSuffix: proxy.portSuffix,
13520
+ tls: proxy.tls,
13521
+ routes: []
13522
+ });
13523
+ }
13524
+ let base = proxy.base || "/";
13525
+ if (!base.startsWith("/"))
13526
+ base = `/${base}`;
13527
+ if (base !== "/" && !base.endsWith("/"))
13528
+ base = `${base}/`;
13529
+ hostsMap.get(key).routes.push({ ...proxy, base });
13530
+ }
13531
+ for (const host of hostsMap.values())
13532
+ host.routes.sort((a, b) => b.base.length - a.base.length);
13533
+ const hosts = Array.from(hostsMap.values());
13534
+ return await liquid.parseAndRender(caddyTemplate, { ...ctx, hosts });
13505
13535
  }
13506
13536
 
13507
13537
  // src/caddy/config.ts
@@ -13640,7 +13670,7 @@ var supportList = [
13640
13670
  // src/caddy/config.ts
13641
13671
  function useCaddyConfig() {
13642
13672
  const configContentRef = signal("{}");
13643
- const configJsonRef2 = computed(() => {
13673
+ const configJsonRef = computed(() => {
13644
13674
  try {
13645
13675
  return JSON.parse(configContentRef());
13646
13676
  } catch {
@@ -13663,26 +13693,31 @@ function useCaddyConfig() {
13663
13693
  const watchCaddyConfig = (0, import_node_fs2.watch)(caddyConfigPath, () => {
13664
13694
  setConfigContent();
13665
13695
  });
13666
- function writeCaddyConfig2(_proxies) {
13667
- const proxies = configJsonRef2() || {};
13696
+ function writeCaddyConfig(_proxies) {
13697
+ const proxies = configJsonRef() || {};
13668
13698
  _proxies.forEach((p) => {
13669
- const index = `${p.target}${p.port_suffix}`;
13670
- proxies[index] = p;
13699
+ let base = p.base || "/";
13700
+ if (!base.startsWith("/"))
13701
+ base = `/${base}`;
13702
+ if (base !== "/" && !base.endsWith("/"))
13703
+ base = `${base}/`;
13704
+ const index = `${p.target}${p.portSuffix}${base}`;
13705
+ proxies[index] = { ...p, base };
13671
13706
  });
13672
13707
  const content = JSON.stringify(proxies, null, 2);
13673
13708
  configContentRef(content);
13674
13709
  return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
13675
13710
  }
13676
- async function cleanUp2() {
13711
+ async function cleanUp() {
13677
13712
  await (0, import_promises2.unlink)(caddyConfigPath).catch(() => {
13678
13713
  });
13679
13714
  configContentRef("{}");
13680
13715
  watchCaddyConfig.close();
13681
13716
  }
13682
13717
  return {
13683
- configJsonRef: configJsonRef2,
13684
- writeCaddyConfig: writeCaddyConfig2,
13685
- cleanUp: cleanUp2
13718
+ configJsonRef,
13719
+ writeCaddyConfig,
13720
+ cleanUp
13686
13721
  };
13687
13722
  }
13688
13723
 
@@ -13816,7 +13851,13 @@ function testCaddy() {
13816
13851
  });
13817
13852
  });
13818
13853
  }
13819
- var { cleanUp, configJsonRef, writeCaddyConfig } = useCaddyConfig();
13854
+ var caddyConfig;
13855
+ function getCaddyConfig() {
13856
+ if (!caddyConfig) {
13857
+ caddyConfig = useCaddyConfig();
13858
+ }
13859
+ return caddyConfig;
13860
+ }
13820
13861
  var CaddyInstant = class {
13821
13862
  constructor() {
13822
13863
  this.inited = false;
@@ -13869,7 +13910,7 @@ var CaddyInstant = class {
13869
13910
  base = "/",
13870
13911
  showCaddyLog = false,
13871
13912
  https = false,
13872
- health_check = true
13913
+ healthCheck = true
13873
13914
  } = options || {};
13874
13915
  this._source = source;
13875
13916
  this._target = target;
@@ -13879,28 +13920,37 @@ var CaddyInstant = class {
13879
13920
  throw new Error("update host failed");
13880
13921
  consola.success("update host success\n");
13881
13922
  const targetHost = target.split(":")[0];
13923
+ const normalizeBase = (b) => {
13924
+ let out = b || "/";
13925
+ if (!out.startsWith("/"))
13926
+ out = `/${out}`;
13927
+ if (out !== "/" && !out.endsWith("/"))
13928
+ out = `${out}/`;
13929
+ return out;
13930
+ };
13931
+ const baseNormalized = normalizeBase(base);
13882
13932
  const proxies = [
13883
13933
  {
13884
13934
  target: targetHost,
13885
- port_suffix: https ? "" : ":80",
13935
+ portSuffix: https ? "" : ":80",
13886
13936
  tls: https ? "tls internal" : "",
13887
13937
  source,
13888
- base,
13889
- health_check
13938
+ base: baseNormalized,
13939
+ healthCheck
13890
13940
  }
13891
13941
  ];
13942
+ const { writeCaddyConfig } = getCaddyConfig();
13892
13943
  writeCaddyConfig(proxies);
13893
13944
  this._stopEffects.push(
13894
13945
  effect(async () => {
13946
+ const { configJsonRef } = getCaddyConfig();
13895
13947
  const proxies2 = Object.values(configJsonRef() || {});
13896
- if (!(this.caddyfile || "").includes(`${target.split(":")[0]}${https ? "" : ":80"}`)) {
13897
- const ctx = validateTemplateContext({
13898
- caddy_root: this.caddyRoot,
13899
- proxies: proxies2
13900
- });
13901
- this.caddyfile = await genCaddyfile(ctx);
13902
- await this.writeCaddyfile();
13903
- }
13948
+ const ctx = validateTemplateContext({
13949
+ caddy_root: this.caddyRoot,
13950
+ proxies: proxies2
13951
+ });
13952
+ this.caddyfile = await genCaddyfile(ctx);
13953
+ await this.writeCaddyfile();
13904
13954
  })
13905
13955
  );
13906
13956
  if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
@@ -14026,7 +14076,9 @@ ${line}
14026
14076
  });
14027
14077
  await (0, import_promises3.unlink)(caddyLockFilePath).catch(() => {
14028
14078
  });
14029
- await cleanUp();
14079
+ if (caddyConfig) {
14080
+ await caddyConfig.cleanUp();
14081
+ }
14030
14082
  } catch (e) {
14031
14083
  consola.error(e);
14032
14084
  }
@@ -14126,7 +14178,7 @@ var unpluginFactory = (options) => ({
14126
14178
  }
14127
14179
  },
14128
14180
  webpack(compiler) {
14129
- var _a4, _b3;
14181
+ var _a4, _b3, _c2;
14130
14182
  if (import_node_process5.default.env.NODE_ENV !== "development")
14131
14183
  return;
14132
14184
  const {
@@ -14157,7 +14209,16 @@ var unpluginFactory = (options) => ({
14157
14209
  const source = `${devServer.host}:${devServer.port}`;
14158
14210
  if (caddy)
14159
14211
  return;
14160
- const _close = (_b3 = compiler.close) == null ? void 0 : _b3.bind(compiler);
14212
+ let base = "/";
14213
+ const publicPath = (_b3 = compiler.options.output) == null ? void 0 : _b3.publicPath;
14214
+ if (typeof publicPath === "string" && publicPath) {
14215
+ base = publicPath;
14216
+ }
14217
+ if (!base.startsWith("/"))
14218
+ base = `/${base}`;
14219
+ if (base !== "/" && !base.endsWith("/"))
14220
+ base = `${base}/`;
14221
+ const _close = (_c2 = compiler.close) == null ? void 0 : _c2.bind(compiler);
14161
14222
  if (_close) {
14162
14223
  compiler.close = async (callback) => {
14163
14224
  import_node_process5.default.on("exit", () => {
@@ -14169,18 +14230,19 @@ var unpluginFactory = (options) => ({
14169
14230
  }
14170
14231
  caddy = new CaddyInstant();
14171
14232
  caddy.run(source, target, {
14233
+ base,
14172
14234
  ...options
14173
14235
  }).then(() => {
14174
14236
  compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
14175
14237
  await printForwardProxy();
14176
- consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
14238
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
14177
14239
  });
14178
14240
  }).catch((e) => {
14179
14241
  throw e;
14180
14242
  });
14181
14243
  },
14182
14244
  async rspack(compiler) {
14183
- var _a4, _b3, _c2;
14245
+ var _a4, _b3, _c2, _d2;
14184
14246
  if (import_node_process5.default.env.NODE_ENV !== "development")
14185
14247
  return;
14186
14248
  const {
@@ -14213,11 +14275,21 @@ var unpluginFactory = (options) => ({
14213
14275
  if (caddy)
14214
14276
  return;
14215
14277
  caddy = new CaddyInstant();
14278
+ let base = "/";
14279
+ const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
14280
+ if (typeof publicPath === "string" && publicPath) {
14281
+ base = publicPath;
14282
+ }
14283
+ if (!base.startsWith("/"))
14284
+ base = `/${base}`;
14285
+ if (base !== "/" && !base.endsWith("/"))
14286
+ base = `${base}/`;
14216
14287
  caddy.run(source, target, {
14288
+ base,
14217
14289
  ...options
14218
14290
  }).then(async () => {
14219
14291
  await printForwardProxy();
14220
- consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
14292
+ consola.success(` ${import_picocolors2.default.green("\u279C")} ${import_picocolors2.default.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
14221
14293
  }).catch((e) => {
14222
14294
  throw e;
14223
14295
  });
package/dist/rspack.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  src_default
3
- } from "./chunk-XGTVAT6M.js";
3
+ } from "./chunk-K7HSLE6X.js";
4
4
  import "./chunk-2P7SUCQ3.js";
5
5
 
6
6
  // src/rspack.ts
package/dist/types.d.cts CHANGED
@@ -4,7 +4,7 @@ interface Options {
4
4
  showCaddyLog?: boolean;
5
5
  /** default `false` */
6
6
  https?: boolean;
7
- health_check?: boolean;
7
+ healthCheck?: boolean;
8
8
  }
9
9
 
10
10
  export type { Options };
package/dist/types.d.ts CHANGED
@@ -4,7 +4,7 @@ interface Options {
4
4
  showCaddyLog?: boolean;
5
5
  /** default `false` */
6
6
  https?: boolean;
7
- health_check?: boolean;
7
+ healthCheck?: boolean;
8
8
  }
9
9
 
10
10
  export type { Options };