unplugin-https-reverse-proxy 3.0.0 → 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/README.md +6 -1
- package/dist/{chunk-5MC5SB7O.js → chunk-K7HSLE6X.js} +96 -34
- package/dist/esbuild.cjs +96 -34
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +96 -34
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +71 -29
- package/dist/nuxt.js +1 -1
- package/dist/rollup.cjs +96 -34
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +96 -34
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +96 -34
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +96 -34
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/caddyfile.ts +58 -19
- package/src/caddy/config.ts +7 -2
- package/src/caddy/index.ts +17 -10
- package/src/index.ts +24 -2
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -13477,33 +13477,63 @@ var caddyTemplate = `{
|
|
|
13477
13477
|
}
|
|
13478
13478
|
}
|
|
13479
13479
|
|
|
13480
|
-
{% for
|
|
13481
|
-
{{
|
|
13482
|
-
{{
|
|
13483
|
-
reverse_proxy http://{{ p.source }} {% if p.healthCheck %} {
|
|
13484
|
-
health_uri {{ p.base }}
|
|
13485
|
-
health_interval 2s
|
|
13486
|
-
health_timeout 5s
|
|
13487
|
-
fail_duration 2s
|
|
13488
|
-
unhealthy_status 502 503 504 404
|
|
13489
|
-
lb_try_duration 3s
|
|
13490
|
-
lb_try_interval 300ms
|
|
13480
|
+
{% for host in hosts %}
|
|
13481
|
+
{{ host.host }}{{ host.portSuffix }} {
|
|
13482
|
+
{{ host.tls }}
|
|
13491
13483
|
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
13496
|
-
|
|
13484
|
+
{% for route in host.routes %}
|
|
13485
|
+
handle {{ route.base }}* {
|
|
13486
|
+
reverse_proxy http://{{ route.source }} {% if route.healthCheck %} {
|
|
13487
|
+
health_uri {{ route.base }}
|
|
13488
|
+
health_interval 2s
|
|
13489
|
+
health_timeout 5s
|
|
13490
|
+
health_headers {
|
|
13491
|
+
User-Agent {http.request.header.User-Agent}
|
|
13492
|
+
Accept text/html,application/json,*/*
|
|
13493
|
+
}
|
|
13494
|
+
fail_duration 2s
|
|
13495
|
+
unhealthy_status 502 503 504 404
|
|
13496
|
+
lb_try_duration 3s
|
|
13497
|
+
lb_try_interval 300ms
|
|
13498
|
+
|
|
13499
|
+
@error status 502 503 504 404
|
|
13500
|
+
handle_response @error {
|
|
13501
|
+
respond * 503 {
|
|
13502
|
+
body "Service Unavailable"
|
|
13503
|
+
close
|
|
13504
|
+
}
|
|
13497
13505
|
}
|
|
13498
13506
|
}
|
|
13507
|
+
{% endif %}
|
|
13499
13508
|
}
|
|
13500
|
-
{%
|
|
13509
|
+
{% endfor %}
|
|
13501
13510
|
}
|
|
13502
13511
|
{% endfor %}
|
|
13503
13512
|
`;
|
|
13504
13513
|
var liquid = new Liquid();
|
|
13505
13514
|
async function genCaddyfile(ctx) {
|
|
13506
|
-
|
|
13515
|
+
const hostsMap = /* @__PURE__ */ new Map();
|
|
13516
|
+
for (const proxy of ctx.proxies) {
|
|
13517
|
+
const key = `${proxy.target}${proxy.portSuffix}`;
|
|
13518
|
+
if (!hostsMap.has(key)) {
|
|
13519
|
+
hostsMap.set(key, {
|
|
13520
|
+
host: proxy.target,
|
|
13521
|
+
portSuffix: proxy.portSuffix,
|
|
13522
|
+
tls: proxy.tls,
|
|
13523
|
+
routes: []
|
|
13524
|
+
});
|
|
13525
|
+
}
|
|
13526
|
+
let base = proxy.base || "/";
|
|
13527
|
+
if (!base.startsWith("/"))
|
|
13528
|
+
base = `/${base}`;
|
|
13529
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
13530
|
+
base = `${base}/`;
|
|
13531
|
+
hostsMap.get(key).routes.push({ ...proxy, base });
|
|
13532
|
+
}
|
|
13533
|
+
for (const host of hostsMap.values())
|
|
13534
|
+
host.routes.sort((a, b) => b.base.length - a.base.length);
|
|
13535
|
+
const hosts = Array.from(hostsMap.values());
|
|
13536
|
+
return await liquid.parseAndRender(caddyTemplate, { ...ctx, hosts });
|
|
13507
13537
|
}
|
|
13508
13538
|
|
|
13509
13539
|
// src/caddy/config.ts
|
|
@@ -13668,8 +13698,13 @@ function useCaddyConfig() {
|
|
|
13668
13698
|
function writeCaddyConfig(_proxies) {
|
|
13669
13699
|
const proxies = configJsonRef() || {};
|
|
13670
13700
|
_proxies.forEach((p) => {
|
|
13671
|
-
|
|
13672
|
-
|
|
13701
|
+
let base = p.base || "/";
|
|
13702
|
+
if (!base.startsWith("/"))
|
|
13703
|
+
base = `/${base}`;
|
|
13704
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
13705
|
+
base = `${base}/`;
|
|
13706
|
+
const index = `${p.target}${p.portSuffix}${base}`;
|
|
13707
|
+
proxies[index] = { ...p, base };
|
|
13673
13708
|
});
|
|
13674
13709
|
const content = JSON.stringify(proxies, null, 2);
|
|
13675
13710
|
configContentRef(content);
|
|
@@ -13887,13 +13922,22 @@ var CaddyInstant = class {
|
|
|
13887
13922
|
throw new Error("update host failed");
|
|
13888
13923
|
consola.success("update host success\n");
|
|
13889
13924
|
const targetHost = target.split(":")[0];
|
|
13925
|
+
const normalizeBase = (b) => {
|
|
13926
|
+
let out = b || "/";
|
|
13927
|
+
if (!out.startsWith("/"))
|
|
13928
|
+
out = `/${out}`;
|
|
13929
|
+
if (out !== "/" && !out.endsWith("/"))
|
|
13930
|
+
out = `${out}/`;
|
|
13931
|
+
return out;
|
|
13932
|
+
};
|
|
13933
|
+
const baseNormalized = normalizeBase(base);
|
|
13890
13934
|
const proxies = [
|
|
13891
13935
|
{
|
|
13892
13936
|
target: targetHost,
|
|
13893
13937
|
portSuffix: https ? "" : ":80",
|
|
13894
13938
|
tls: https ? "tls internal" : "",
|
|
13895
13939
|
source,
|
|
13896
|
-
base,
|
|
13940
|
+
base: baseNormalized,
|
|
13897
13941
|
healthCheck
|
|
13898
13942
|
}
|
|
13899
13943
|
];
|
|
@@ -13903,14 +13947,12 @@ var CaddyInstant = class {
|
|
|
13903
13947
|
effect(async () => {
|
|
13904
13948
|
const { configJsonRef } = getCaddyConfig();
|
|
13905
13949
|
const proxies2 = Object.values(configJsonRef() || {});
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13910
|
-
|
|
13911
|
-
|
|
13912
|
-
await this.writeCaddyfile();
|
|
13913
|
-
}
|
|
13950
|
+
const ctx = validateTemplateContext({
|
|
13951
|
+
caddy_root: this.caddyRoot,
|
|
13952
|
+
proxies: proxies2
|
|
13953
|
+
});
|
|
13954
|
+
this.caddyfile = await genCaddyfile(ctx);
|
|
13955
|
+
await this.writeCaddyfile();
|
|
13914
13956
|
})
|
|
13915
13957
|
);
|
|
13916
13958
|
if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
|
package/dist/nuxt.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -13476,33 +13476,63 @@ var caddyTemplate = `{
|
|
|
13476
13476
|
}
|
|
13477
13477
|
}
|
|
13478
13478
|
|
|
13479
|
-
{% for
|
|
13480
|
-
{{
|
|
13481
|
-
{{
|
|
13482
|
-
reverse_proxy http://{{ p.source }} {% if p.healthCheck %} {
|
|
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
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13495
|
-
|
|
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
|
-
{%
|
|
13508
|
+
{% endfor %}
|
|
13500
13509
|
}
|
|
13501
13510
|
{% endfor %}
|
|
13502
13511
|
`;
|
|
13503
13512
|
var liquid = new Liquid();
|
|
13504
13513
|
async function genCaddyfile(ctx) {
|
|
13505
|
-
|
|
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
|
|
@@ -13667,8 +13697,13 @@ function useCaddyConfig() {
|
|
|
13667
13697
|
function writeCaddyConfig(_proxies) {
|
|
13668
13698
|
const proxies = configJsonRef() || {};
|
|
13669
13699
|
_proxies.forEach((p) => {
|
|
13670
|
-
|
|
13671
|
-
|
|
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);
|
|
@@ -13886,13 +13921,22 @@ var CaddyInstant = class {
|
|
|
13886
13921
|
throw new Error("update host failed");
|
|
13887
13922
|
consola.success("update host success\n");
|
|
13888
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);
|
|
13889
13933
|
const proxies = [
|
|
13890
13934
|
{
|
|
13891
13935
|
target: targetHost,
|
|
13892
13936
|
portSuffix: https ? "" : ":80",
|
|
13893
13937
|
tls: https ? "tls internal" : "",
|
|
13894
13938
|
source,
|
|
13895
|
-
base,
|
|
13939
|
+
base: baseNormalized,
|
|
13896
13940
|
healthCheck
|
|
13897
13941
|
}
|
|
13898
13942
|
];
|
|
@@ -13902,14 +13946,12 @@ var CaddyInstant = class {
|
|
|
13902
13946
|
effect(async () => {
|
|
13903
13947
|
const { configJsonRef } = getCaddyConfig();
|
|
13904
13948
|
const proxies2 = Object.values(configJsonRef() || {});
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13910
|
-
|
|
13911
|
-
await this.writeCaddyfile();
|
|
13912
|
-
}
|
|
13949
|
+
const ctx = validateTemplateContext({
|
|
13950
|
+
caddy_root: this.caddyRoot,
|
|
13951
|
+
proxies: proxies2
|
|
13952
|
+
});
|
|
13953
|
+
this.caddyfile = await genCaddyfile(ctx);
|
|
13954
|
+
await this.writeCaddyfile();
|
|
13913
13955
|
})
|
|
13914
13956
|
);
|
|
13915
13957
|
if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
|
|
@@ -14137,7 +14179,7 @@ var unpluginFactory = (options) => ({
|
|
|
14137
14179
|
}
|
|
14138
14180
|
},
|
|
14139
14181
|
webpack(compiler) {
|
|
14140
|
-
var _a4, _b3;
|
|
14182
|
+
var _a4, _b3, _c2;
|
|
14141
14183
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
14142
14184
|
return;
|
|
14143
14185
|
const {
|
|
@@ -14168,7 +14210,16 @@ var unpluginFactory = (options) => ({
|
|
|
14168
14210
|
const source = `${devServer.host}:${devServer.port}`;
|
|
14169
14211
|
if (caddy)
|
|
14170
14212
|
return;
|
|
14171
|
-
|
|
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);
|
|
14172
14223
|
if (_close) {
|
|
14173
14224
|
compiler.close = async (callback) => {
|
|
14174
14225
|
import_node_process5.default.on("exit", () => {
|
|
@@ -14180,18 +14231,19 @@ var unpluginFactory = (options) => ({
|
|
|
14180
14231
|
}
|
|
14181
14232
|
caddy = new CaddyInstant();
|
|
14182
14233
|
caddy.run(source, target, {
|
|
14234
|
+
base,
|
|
14183
14235
|
...options
|
|
14184
14236
|
}).then(() => {
|
|
14185
14237
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
|
|
14186
14238
|
await printForwardProxy();
|
|
14187
|
-
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}`)}`);
|
|
14188
14240
|
});
|
|
14189
14241
|
}).catch((e) => {
|
|
14190
14242
|
throw e;
|
|
14191
14243
|
});
|
|
14192
14244
|
},
|
|
14193
14245
|
async rspack(compiler) {
|
|
14194
|
-
var _a4, _b3, _c2;
|
|
14246
|
+
var _a4, _b3, _c2, _d2;
|
|
14195
14247
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
14196
14248
|
return;
|
|
14197
14249
|
const {
|
|
@@ -14224,11 +14276,21 @@ var unpluginFactory = (options) => ({
|
|
|
14224
14276
|
if (caddy)
|
|
14225
14277
|
return;
|
|
14226
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}/`;
|
|
14227
14288
|
caddy.run(source, target, {
|
|
14289
|
+
base,
|
|
14228
14290
|
...options
|
|
14229
14291
|
}).then(async () => {
|
|
14230
14292
|
await printForwardProxy();
|
|
14231
|
-
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}`)}`);
|
|
14232
14294
|
}).catch((e) => {
|
|
14233
14295
|
throw e;
|
|
14234
14296
|
});
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -13475,33 +13475,63 @@ var caddyTemplate = `{
|
|
|
13475
13475
|
}
|
|
13476
13476
|
}
|
|
13477
13477
|
|
|
13478
|
-
{% for
|
|
13479
|
-
{{
|
|
13480
|
-
{{
|
|
13481
|
-
reverse_proxy http://{{ p.source }} {% if p.healthCheck %} {
|
|
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
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
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
|
-
{%
|
|
13507
|
+
{% endfor %}
|
|
13499
13508
|
}
|
|
13500
13509
|
{% endfor %}
|
|
13501
13510
|
`;
|
|
13502
13511
|
var liquid = new Liquid();
|
|
13503
13512
|
async function genCaddyfile(ctx) {
|
|
13504
|
-
|
|
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
|
|
@@ -13666,8 +13696,13 @@ function useCaddyConfig() {
|
|
|
13666
13696
|
function writeCaddyConfig(_proxies) {
|
|
13667
13697
|
const proxies = configJsonRef() || {};
|
|
13668
13698
|
_proxies.forEach((p) => {
|
|
13669
|
-
|
|
13670
|
-
|
|
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);
|
|
@@ -13885,13 +13920,22 @@ var CaddyInstant = class {
|
|
|
13885
13920
|
throw new Error("update host failed");
|
|
13886
13921
|
consola.success("update host success\n");
|
|
13887
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);
|
|
13888
13932
|
const proxies = [
|
|
13889
13933
|
{
|
|
13890
13934
|
target: targetHost,
|
|
13891
13935
|
portSuffix: https ? "" : ":80",
|
|
13892
13936
|
tls: https ? "tls internal" : "",
|
|
13893
13937
|
source,
|
|
13894
|
-
base,
|
|
13938
|
+
base: baseNormalized,
|
|
13895
13939
|
healthCheck
|
|
13896
13940
|
}
|
|
13897
13941
|
];
|
|
@@ -13901,14 +13945,12 @@ var CaddyInstant = class {
|
|
|
13901
13945
|
effect(async () => {
|
|
13902
13946
|
const { configJsonRef } = getCaddyConfig();
|
|
13903
13947
|
const proxies2 = Object.values(configJsonRef() || {});
|
|
13904
|
-
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
13908
|
-
|
|
13909
|
-
|
|
13910
|
-
await this.writeCaddyfile();
|
|
13911
|
-
}
|
|
13948
|
+
const ctx = validateTemplateContext({
|
|
13949
|
+
caddy_root: this.caddyRoot,
|
|
13950
|
+
proxies: proxies2
|
|
13951
|
+
});
|
|
13952
|
+
this.caddyfile = await genCaddyfile(ctx);
|
|
13953
|
+
await this.writeCaddyfile();
|
|
13912
13954
|
})
|
|
13913
13955
|
);
|
|
13914
13956
|
if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
|
|
@@ -14136,7 +14178,7 @@ var unpluginFactory = (options) => ({
|
|
|
14136
14178
|
}
|
|
14137
14179
|
},
|
|
14138
14180
|
webpack(compiler) {
|
|
14139
|
-
var _a4, _b3;
|
|
14181
|
+
var _a4, _b3, _c2;
|
|
14140
14182
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
14141
14183
|
return;
|
|
14142
14184
|
const {
|
|
@@ -14167,7 +14209,16 @@ var unpluginFactory = (options) => ({
|
|
|
14167
14209
|
const source = `${devServer.host}:${devServer.port}`;
|
|
14168
14210
|
if (caddy)
|
|
14169
14211
|
return;
|
|
14170
|
-
|
|
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);
|
|
14171
14222
|
if (_close) {
|
|
14172
14223
|
compiler.close = async (callback) => {
|
|
14173
14224
|
import_node_process5.default.on("exit", () => {
|
|
@@ -14179,18 +14230,19 @@ var unpluginFactory = (options) => ({
|
|
|
14179
14230
|
}
|
|
14180
14231
|
caddy = new CaddyInstant();
|
|
14181
14232
|
caddy.run(source, target, {
|
|
14233
|
+
base,
|
|
14182
14234
|
...options
|
|
14183
14235
|
}).then(() => {
|
|
14184
14236
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
|
|
14185
14237
|
await printForwardProxy();
|
|
14186
|
-
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}`)}`);
|
|
14187
14239
|
});
|
|
14188
14240
|
}).catch((e) => {
|
|
14189
14241
|
throw e;
|
|
14190
14242
|
});
|
|
14191
14243
|
},
|
|
14192
14244
|
async rspack(compiler) {
|
|
14193
|
-
var _a4, _b3, _c2;
|
|
14245
|
+
var _a4, _b3, _c2, _d2;
|
|
14194
14246
|
if (import_node_process5.default.env.NODE_ENV !== "development")
|
|
14195
14247
|
return;
|
|
14196
14248
|
const {
|
|
@@ -14223,11 +14275,21 @@ var unpluginFactory = (options) => ({
|
|
|
14223
14275
|
if (caddy)
|
|
14224
14276
|
return;
|
|
14225
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}/`;
|
|
14226
14287
|
caddy.run(source, target, {
|
|
14288
|
+
base,
|
|
14227
14289
|
...options
|
|
14228
14290
|
}).then(async () => {
|
|
14229
14291
|
await printForwardProxy();
|
|
14230
|
-
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}`)}`);
|
|
14231
14293
|
}).catch((e) => {
|
|
14232
14294
|
throw e;
|
|
14233
14295
|
});
|