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/README.md +6 -1
- package/dist/{chunk-XGTVAT6M.js → chunk-K7HSLE6X.js} +120 -48
- package/dist/esbuild.cjs +120 -48
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +120 -48
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +95 -43
- package/dist/nuxt.js +1 -1
- package/dist/rollup.cjs +120 -48
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +120 -48
- package/dist/rspack.js +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/vite.cjs +120 -48
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +120 -48
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/src/caddy/caddyfile.ts +60 -21
- package/src/caddy/config.ts +7 -2
- package/src/caddy/index.ts +34 -16
- package/src/index.ts +24 -2
- package/src/types.ts +1 -1
package/dist/index.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
|
-
|
|
13440
|
+
portSuffix: "string",
|
|
13441
13441
|
tls: "string",
|
|
13442
13442
|
source: "string",
|
|
13443
13443
|
base: "string",
|
|
13444
|
-
|
|
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
|
|
13480
|
-
{{
|
|
13481
|
-
{{
|
|
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
|
-
|
|
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
|
|
@@ -13641,7 +13671,7 @@ var supportList = [
|
|
|
13641
13671
|
// src/caddy/config.ts
|
|
13642
13672
|
function useCaddyConfig() {
|
|
13643
13673
|
const configContentRef = signal("{}");
|
|
13644
|
-
const
|
|
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
|
|
13668
|
-
const proxies =
|
|
13697
|
+
function writeCaddyConfig(_proxies) {
|
|
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);
|
|
13675
13710
|
return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
|
|
13676
13711
|
}
|
|
13677
|
-
async function
|
|
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
|
|
13685
|
-
writeCaddyConfig
|
|
13686
|
-
cleanUp
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
13936
|
+
portSuffix: https ? "" : ":80",
|
|
13887
13937
|
tls: https ? "tls internal" : "",
|
|
13888
13938
|
source,
|
|
13889
|
-
base,
|
|
13890
|
-
|
|
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
|
-
|
|
13898
|
-
|
|
13899
|
-
|
|
13900
|
-
|
|
13901
|
-
|
|
13902
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -13438,11 +13438,11 @@ var Liquid = class _Liquid {
|
|
|
13438
13438
|
// src/caddy/caddyfile.ts
|
|
13439
13439
|
var ProxyType = type({
|
|
13440
13440
|
target: "string",
|
|
13441
|
-
|
|
13441
|
+
portSuffix: "string",
|
|
13442
13442
|
tls: "string",
|
|
13443
13443
|
source: "string",
|
|
13444
13444
|
base: "string",
|
|
13445
|
-
|
|
13445
|
+
healthCheck: "boolean"
|
|
13446
13446
|
});
|
|
13447
13447
|
var CaddyContext = type({
|
|
13448
13448
|
caddy_root: "string",
|
|
@@ -13477,33 +13477,63 @@ var caddyTemplate = `{
|
|
|
13477
13477
|
}
|
|
13478
13478
|
}
|
|
13479
13479
|
|
|
13480
|
-
{% for
|
|
13481
|
-
{{
|
|
13482
|
-
{{
|
|
13483
|
-
reverse_proxy http://{{ p.source }} {% if p.health_check %} {
|
|
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
|
|
@@ -13642,7 +13672,7 @@ var supportList = [
|
|
|
13642
13672
|
// src/caddy/config.ts
|
|
13643
13673
|
function useCaddyConfig() {
|
|
13644
13674
|
const configContentRef = signal("{}");
|
|
13645
|
-
const
|
|
13675
|
+
const configJsonRef = computed(() => {
|
|
13646
13676
|
try {
|
|
13647
13677
|
return JSON.parse(configContentRef());
|
|
13648
13678
|
} catch {
|
|
@@ -13665,26 +13695,31 @@ function useCaddyConfig() {
|
|
|
13665
13695
|
const watchCaddyConfig = (0, import_node_fs2.watch)(caddyConfigPath, () => {
|
|
13666
13696
|
setConfigContent();
|
|
13667
13697
|
});
|
|
13668
|
-
function
|
|
13669
|
-
const proxies =
|
|
13698
|
+
function writeCaddyConfig(_proxies) {
|
|
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);
|
|
13676
13711
|
return (0, import_node_fs2.writeFileSync)(caddyConfigPath, content);
|
|
13677
13712
|
}
|
|
13678
|
-
async function
|
|
13713
|
+
async function cleanUp() {
|
|
13679
13714
|
await (0, import_promises2.unlink)(caddyConfigPath).catch(() => {
|
|
13680
13715
|
});
|
|
13681
13716
|
configContentRef("{}");
|
|
13682
13717
|
watchCaddyConfig.close();
|
|
13683
13718
|
}
|
|
13684
13719
|
return {
|
|
13685
|
-
configJsonRef
|
|
13686
|
-
writeCaddyConfig
|
|
13687
|
-
cleanUp
|
|
13720
|
+
configJsonRef,
|
|
13721
|
+
writeCaddyConfig,
|
|
13722
|
+
cleanUp
|
|
13688
13723
|
};
|
|
13689
13724
|
}
|
|
13690
13725
|
|
|
@@ -13818,7 +13853,13 @@ function testCaddy() {
|
|
|
13818
13853
|
});
|
|
13819
13854
|
});
|
|
13820
13855
|
}
|
|
13821
|
-
var
|
|
13856
|
+
var caddyConfig;
|
|
13857
|
+
function getCaddyConfig() {
|
|
13858
|
+
if (!caddyConfig) {
|
|
13859
|
+
caddyConfig = useCaddyConfig();
|
|
13860
|
+
}
|
|
13861
|
+
return caddyConfig;
|
|
13862
|
+
}
|
|
13822
13863
|
var CaddyInstant = class {
|
|
13823
13864
|
constructor() {
|
|
13824
13865
|
this.inited = false;
|
|
@@ -13871,7 +13912,7 @@ var CaddyInstant = class {
|
|
|
13871
13912
|
base = "/",
|
|
13872
13913
|
showCaddyLog = false,
|
|
13873
13914
|
https = false,
|
|
13874
|
-
|
|
13915
|
+
healthCheck = true
|
|
13875
13916
|
} = options || {};
|
|
13876
13917
|
this._source = source;
|
|
13877
13918
|
this._target = target;
|
|
@@ -13881,28 +13922,37 @@ var CaddyInstant = class {
|
|
|
13881
13922
|
throw new Error("update host failed");
|
|
13882
13923
|
consola.success("update host success\n");
|
|
13883
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);
|
|
13884
13934
|
const proxies = [
|
|
13885
13935
|
{
|
|
13886
13936
|
target: targetHost,
|
|
13887
|
-
|
|
13937
|
+
portSuffix: https ? "" : ":80",
|
|
13888
13938
|
tls: https ? "tls internal" : "",
|
|
13889
13939
|
source,
|
|
13890
|
-
base,
|
|
13891
|
-
|
|
13940
|
+
base: baseNormalized,
|
|
13941
|
+
healthCheck
|
|
13892
13942
|
}
|
|
13893
13943
|
];
|
|
13944
|
+
const { writeCaddyConfig } = getCaddyConfig();
|
|
13894
13945
|
writeCaddyConfig(proxies);
|
|
13895
13946
|
this._stopEffects.push(
|
|
13896
13947
|
effect(async () => {
|
|
13948
|
+
const { configJsonRef } = getCaddyConfig();
|
|
13897
13949
|
const proxies2 = Object.values(configJsonRef() || {});
|
|
13898
|
-
|
|
13899
|
-
|
|
13900
|
-
|
|
13901
|
-
|
|
13902
|
-
|
|
13903
|
-
|
|
13904
|
-
await this.writeCaddyfile();
|
|
13905
|
-
}
|
|
13950
|
+
const ctx = validateTemplateContext({
|
|
13951
|
+
caddy_root: this.caddyRoot,
|
|
13952
|
+
proxies: proxies2
|
|
13953
|
+
});
|
|
13954
|
+
this.caddyfile = await genCaddyfile(ctx);
|
|
13955
|
+
await this.writeCaddyfile();
|
|
13906
13956
|
})
|
|
13907
13957
|
);
|
|
13908
13958
|
if (!(0, import_node_fs3.existsSync)(caddyLockFilePath))
|
|
@@ -14028,7 +14078,9 @@ ${line}
|
|
|
14028
14078
|
});
|
|
14029
14079
|
await (0, import_promises3.unlink)(caddyLockFilePath).catch(() => {
|
|
14030
14080
|
});
|
|
14031
|
-
|
|
14081
|
+
if (caddyConfig) {
|
|
14082
|
+
await caddyConfig.cleanUp();
|
|
14083
|
+
}
|
|
14032
14084
|
} catch (e) {
|
|
14033
14085
|
consola.error(e);
|
|
14034
14086
|
}
|