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/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# unplugin-https-reverse-proxy
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/unplugin-https-reverse-proxy)
|
|
4
|
+
[](https://deepwiki.com/zcf0508/unplugin-https-reverse-proxy)
|
|
4
5
|
|
|
5
6
|
A plugin for https reverse proxy, support `vite`、`webpack` and `rspack`.
|
|
6
7
|
|
|
@@ -170,6 +171,7 @@ const reverseProxyOptions = {
|
|
|
170
171
|
enable: false,
|
|
171
172
|
target: 'xxx',
|
|
172
173
|
https: false,
|
|
174
|
+
healthCheck: true,
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
module.exports = {
|
|
@@ -209,7 +211,10 @@ module.exports = {
|
|
|
209
211
|
// nuxt.config.js
|
|
210
212
|
export default defineNuxtConfig({
|
|
211
213
|
modules: [
|
|
212
|
-
['unplugin-https-reverse-proxy/nuxt', {
|
|
214
|
+
['unplugin-https-reverse-proxy/nuxt', {
|
|
215
|
+
/* options */
|
|
216
|
+
healthCheck: false, // important for nuxt
|
|
217
|
+
}],
|
|
213
218
|
],
|
|
214
219
|
})
|
|
215
220
|
```
|
|
@@ -13352,11 +13352,11 @@ var Liquid = class _Liquid {
|
|
|
13352
13352
|
// src/caddy/caddyfile.ts
|
|
13353
13353
|
var ProxyType = type({
|
|
13354
13354
|
target: "string",
|
|
13355
|
-
|
|
13355
|
+
portSuffix: "string",
|
|
13356
13356
|
tls: "string",
|
|
13357
13357
|
source: "string",
|
|
13358
13358
|
base: "string",
|
|
13359
|
-
|
|
13359
|
+
healthCheck: "boolean"
|
|
13360
13360
|
});
|
|
13361
13361
|
var CaddyContext = type({
|
|
13362
13362
|
caddy_root: "string",
|
|
@@ -13391,33 +13391,63 @@ var caddyTemplate = `{
|
|
|
13391
13391
|
}
|
|
13392
13392
|
}
|
|
13393
13393
|
|
|
13394
|
-
{% for
|
|
13395
|
-
{{
|
|
13396
|
-
{{
|
|
13397
|
-
reverse_proxy http://{{ p.source }} {% if p.health_check %} {
|
|
13398
|
-
health_uri {{ p.base }}
|
|
13399
|
-
health_interval 2s
|
|
13400
|
-
health_timeout 5s
|
|
13401
|
-
fail_duration 2s
|
|
13402
|
-
unhealthy_status 502 503 504 404
|
|
13403
|
-
lb_try_duration 3s
|
|
13404
|
-
lb_try_interval 300ms
|
|
13394
|
+
{% for host in hosts %}
|
|
13395
|
+
{{ host.host }}{{ host.portSuffix }} {
|
|
13396
|
+
{{ host.tls }}
|
|
13405
13397
|
|
|
13406
|
-
|
|
13407
|
-
|
|
13408
|
-
|
|
13409
|
-
|
|
13410
|
-
|
|
13398
|
+
{% for route in host.routes %}
|
|
13399
|
+
handle {{ route.base }}* {
|
|
13400
|
+
reverse_proxy http://{{ route.source }} {% if route.healthCheck %} {
|
|
13401
|
+
health_uri {{ route.base }}
|
|
13402
|
+
health_interval 2s
|
|
13403
|
+
health_timeout 5s
|
|
13404
|
+
health_headers {
|
|
13405
|
+
User-Agent {http.request.header.User-Agent}
|
|
13406
|
+
Accept text/html,application/json,*/*
|
|
13407
|
+
}
|
|
13408
|
+
fail_duration 2s
|
|
13409
|
+
unhealthy_status 502 503 504 404
|
|
13410
|
+
lb_try_duration 3s
|
|
13411
|
+
lb_try_interval 300ms
|
|
13412
|
+
|
|
13413
|
+
@error status 502 503 504 404
|
|
13414
|
+
handle_response @error {
|
|
13415
|
+
respond * 503 {
|
|
13416
|
+
body "Service Unavailable"
|
|
13417
|
+
close
|
|
13418
|
+
}
|
|
13411
13419
|
}
|
|
13412
13420
|
}
|
|
13421
|
+
{% endif %}
|
|
13413
13422
|
}
|
|
13414
|
-
{%
|
|
13423
|
+
{% endfor %}
|
|
13415
13424
|
}
|
|
13416
13425
|
{% endfor %}
|
|
13417
13426
|
`;
|
|
13418
13427
|
var liquid = new Liquid();
|
|
13419
13428
|
async function genCaddyfile(ctx) {
|
|
13420
|
-
|
|
13429
|
+
const hostsMap = /* @__PURE__ */ new Map();
|
|
13430
|
+
for (const proxy of ctx.proxies) {
|
|
13431
|
+
const key = `${proxy.target}${proxy.portSuffix}`;
|
|
13432
|
+
if (!hostsMap.has(key)) {
|
|
13433
|
+
hostsMap.set(key, {
|
|
13434
|
+
host: proxy.target,
|
|
13435
|
+
portSuffix: proxy.portSuffix,
|
|
13436
|
+
tls: proxy.tls,
|
|
13437
|
+
routes: []
|
|
13438
|
+
});
|
|
13439
|
+
}
|
|
13440
|
+
let base = proxy.base || "/";
|
|
13441
|
+
if (!base.startsWith("/"))
|
|
13442
|
+
base = `/${base}`;
|
|
13443
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
13444
|
+
base = `${base}/`;
|
|
13445
|
+
hostsMap.get(key).routes.push({ ...proxy, base });
|
|
13446
|
+
}
|
|
13447
|
+
for (const host of hostsMap.values())
|
|
13448
|
+
host.routes.sort((a, b) => b.base.length - a.base.length);
|
|
13449
|
+
const hosts = Array.from(hostsMap.values());
|
|
13450
|
+
return await liquid.parseAndRender(caddyTemplate, { ...ctx, hosts });
|
|
13421
13451
|
}
|
|
13422
13452
|
|
|
13423
13453
|
// src/caddy/config.ts
|
|
@@ -13556,7 +13586,7 @@ var supportList = [
|
|
|
13556
13586
|
// src/caddy/config.ts
|
|
13557
13587
|
function useCaddyConfig() {
|
|
13558
13588
|
const configContentRef = signal("{}");
|
|
13559
|
-
const
|
|
13589
|
+
const configJsonRef = computed(() => {
|
|
13560
13590
|
try {
|
|
13561
13591
|
return JSON.parse(configContentRef());
|
|
13562
13592
|
} catch {
|
|
@@ -13579,26 +13609,31 @@ function useCaddyConfig() {
|
|
|
13579
13609
|
const watchCaddyConfig = watch(caddyConfigPath, () => {
|
|
13580
13610
|
setConfigContent();
|
|
13581
13611
|
});
|
|
13582
|
-
function
|
|
13583
|
-
const proxies =
|
|
13612
|
+
function writeCaddyConfig(_proxies) {
|
|
13613
|
+
const proxies = configJsonRef() || {};
|
|
13584
13614
|
_proxies.forEach((p) => {
|
|
13585
|
-
|
|
13586
|
-
|
|
13615
|
+
let base = p.base || "/";
|
|
13616
|
+
if (!base.startsWith("/"))
|
|
13617
|
+
base = `/${base}`;
|
|
13618
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
13619
|
+
base = `${base}/`;
|
|
13620
|
+
const index = `${p.target}${p.portSuffix}${base}`;
|
|
13621
|
+
proxies[index] = { ...p, base };
|
|
13587
13622
|
});
|
|
13588
13623
|
const content = JSON.stringify(proxies, null, 2);
|
|
13589
13624
|
configContentRef(content);
|
|
13590
13625
|
return writeFileSync(caddyConfigPath, content);
|
|
13591
13626
|
}
|
|
13592
|
-
async function
|
|
13627
|
+
async function cleanUp() {
|
|
13593
13628
|
await unlink2(caddyConfigPath).catch(() => {
|
|
13594
13629
|
});
|
|
13595
13630
|
configContentRef("{}");
|
|
13596
13631
|
watchCaddyConfig.close();
|
|
13597
13632
|
}
|
|
13598
13633
|
return {
|
|
13599
|
-
configJsonRef
|
|
13600
|
-
writeCaddyConfig
|
|
13601
|
-
cleanUp
|
|
13634
|
+
configJsonRef,
|
|
13635
|
+
writeCaddyConfig,
|
|
13636
|
+
cleanUp
|
|
13602
13637
|
};
|
|
13603
13638
|
}
|
|
13604
13639
|
|
|
@@ -13732,7 +13767,13 @@ function testCaddy() {
|
|
|
13732
13767
|
});
|
|
13733
13768
|
});
|
|
13734
13769
|
}
|
|
13735
|
-
var
|
|
13770
|
+
var caddyConfig;
|
|
13771
|
+
function getCaddyConfig() {
|
|
13772
|
+
if (!caddyConfig) {
|
|
13773
|
+
caddyConfig = useCaddyConfig();
|
|
13774
|
+
}
|
|
13775
|
+
return caddyConfig;
|
|
13776
|
+
}
|
|
13736
13777
|
var CaddyInstant = class {
|
|
13737
13778
|
constructor() {
|
|
13738
13779
|
this.inited = false;
|
|
@@ -13785,7 +13826,7 @@ var CaddyInstant = class {
|
|
|
13785
13826
|
base = "/",
|
|
13786
13827
|
showCaddyLog = false,
|
|
13787
13828
|
https = false,
|
|
13788
|
-
|
|
13829
|
+
healthCheck = true
|
|
13789
13830
|
} = options || {};
|
|
13790
13831
|
this._source = source;
|
|
13791
13832
|
this._target = target;
|
|
@@ -13795,28 +13836,37 @@ var CaddyInstant = class {
|
|
|
13795
13836
|
throw new Error("update host failed");
|
|
13796
13837
|
consola.success("update host success\n");
|
|
13797
13838
|
const targetHost = target.split(":")[0];
|
|
13839
|
+
const normalizeBase = (b) => {
|
|
13840
|
+
let out = b || "/";
|
|
13841
|
+
if (!out.startsWith("/"))
|
|
13842
|
+
out = `/${out}`;
|
|
13843
|
+
if (out !== "/" && !out.endsWith("/"))
|
|
13844
|
+
out = `${out}/`;
|
|
13845
|
+
return out;
|
|
13846
|
+
};
|
|
13847
|
+
const baseNormalized = normalizeBase(base);
|
|
13798
13848
|
const proxies = [
|
|
13799
13849
|
{
|
|
13800
13850
|
target: targetHost,
|
|
13801
|
-
|
|
13851
|
+
portSuffix: https ? "" : ":80",
|
|
13802
13852
|
tls: https ? "tls internal" : "",
|
|
13803
13853
|
source,
|
|
13804
|
-
base,
|
|
13805
|
-
|
|
13854
|
+
base: baseNormalized,
|
|
13855
|
+
healthCheck
|
|
13806
13856
|
}
|
|
13807
13857
|
];
|
|
13858
|
+
const { writeCaddyConfig } = getCaddyConfig();
|
|
13808
13859
|
writeCaddyConfig(proxies);
|
|
13809
13860
|
this._stopEffects.push(
|
|
13810
13861
|
effect(async () => {
|
|
13862
|
+
const { configJsonRef } = getCaddyConfig();
|
|
13811
13863
|
const proxies2 = Object.values(configJsonRef() || {});
|
|
13812
|
-
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
13816
|
-
|
|
13817
|
-
|
|
13818
|
-
await this.writeCaddyfile();
|
|
13819
|
-
}
|
|
13864
|
+
const ctx = validateTemplateContext({
|
|
13865
|
+
caddy_root: this.caddyRoot,
|
|
13866
|
+
proxies: proxies2
|
|
13867
|
+
});
|
|
13868
|
+
this.caddyfile = await genCaddyfile(ctx);
|
|
13869
|
+
await this.writeCaddyfile();
|
|
13820
13870
|
})
|
|
13821
13871
|
);
|
|
13822
13872
|
if (!existsSync3(caddyLockFilePath))
|
|
@@ -13942,7 +13992,9 @@ ${line}
|
|
|
13942
13992
|
});
|
|
13943
13993
|
await unlink3(caddyLockFilePath).catch(() => {
|
|
13944
13994
|
});
|
|
13945
|
-
|
|
13995
|
+
if (caddyConfig) {
|
|
13996
|
+
await caddyConfig.cleanUp();
|
|
13997
|
+
}
|
|
13946
13998
|
} catch (e) {
|
|
13947
13999
|
consola.error(e);
|
|
13948
14000
|
}
|
|
@@ -14042,7 +14094,7 @@ var unpluginFactory = (options) => ({
|
|
|
14042
14094
|
}
|
|
14043
14095
|
},
|
|
14044
14096
|
webpack(compiler) {
|
|
14045
|
-
var _a4, _b3;
|
|
14097
|
+
var _a4, _b3, _c2;
|
|
14046
14098
|
if (process5.env.NODE_ENV !== "development")
|
|
14047
14099
|
return;
|
|
14048
14100
|
const {
|
|
@@ -14073,7 +14125,16 @@ var unpluginFactory = (options) => ({
|
|
|
14073
14125
|
const source = `${devServer.host}:${devServer.port}`;
|
|
14074
14126
|
if (caddy)
|
|
14075
14127
|
return;
|
|
14076
|
-
|
|
14128
|
+
let base = "/";
|
|
14129
|
+
const publicPath = (_b3 = compiler.options.output) == null ? void 0 : _b3.publicPath;
|
|
14130
|
+
if (typeof publicPath === "string" && publicPath) {
|
|
14131
|
+
base = publicPath;
|
|
14132
|
+
}
|
|
14133
|
+
if (!base.startsWith("/"))
|
|
14134
|
+
base = `/${base}`;
|
|
14135
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
14136
|
+
base = `${base}/`;
|
|
14137
|
+
const _close = (_c2 = compiler.close) == null ? void 0 : _c2.bind(compiler);
|
|
14077
14138
|
if (_close) {
|
|
14078
14139
|
compiler.close = async (callback) => {
|
|
14079
14140
|
process5.on("exit", () => {
|
|
@@ -14085,18 +14146,19 @@ var unpluginFactory = (options) => ({
|
|
|
14085
14146
|
}
|
|
14086
14147
|
caddy = new CaddyInstant();
|
|
14087
14148
|
caddy.run(source, target, {
|
|
14149
|
+
base,
|
|
14088
14150
|
...options
|
|
14089
14151
|
}).then(() => {
|
|
14090
14152
|
compiler.hooks.done.tap("unplugin-https-reverse-proxy", async () => {
|
|
14091
14153
|
await printForwardProxy();
|
|
14092
|
-
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
14154
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
14093
14155
|
});
|
|
14094
14156
|
}).catch((e) => {
|
|
14095
14157
|
throw e;
|
|
14096
14158
|
});
|
|
14097
14159
|
},
|
|
14098
14160
|
async rspack(compiler) {
|
|
14099
|
-
var _a4, _b3, _c2;
|
|
14161
|
+
var _a4, _b3, _c2, _d2;
|
|
14100
14162
|
if (process5.env.NODE_ENV !== "development")
|
|
14101
14163
|
return;
|
|
14102
14164
|
const {
|
|
@@ -14129,11 +14191,21 @@ var unpluginFactory = (options) => ({
|
|
|
14129
14191
|
if (caddy)
|
|
14130
14192
|
return;
|
|
14131
14193
|
caddy = new CaddyInstant();
|
|
14194
|
+
let base = "/";
|
|
14195
|
+
const publicPath = (_d2 = compiler.options.output) == null ? void 0 : _d2.publicPath;
|
|
14196
|
+
if (typeof publicPath === "string" && publicPath) {
|
|
14197
|
+
base = publicPath;
|
|
14198
|
+
}
|
|
14199
|
+
if (!base.startsWith("/"))
|
|
14200
|
+
base = `/${base}`;
|
|
14201
|
+
if (base !== "/" && !base.endsWith("/"))
|
|
14202
|
+
base = `${base}/`;
|
|
14132
14203
|
caddy.run(source, target, {
|
|
14204
|
+
base,
|
|
14133
14205
|
...options
|
|
14134
14206
|
}).then(async () => {
|
|
14135
14207
|
await printForwardProxy();
|
|
14136
|
-
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}`)}`);
|
|
14208
|
+
consola.success(` ${c.green("\u279C")} ${c.bold("run caddy reverse proxy success")}: ${colorUrl(`${options.https ? "https" : "http"}://${target}${base}`)}`);
|
|
14137
14209
|
}).catch((e) => {
|
|
14138
14210
|
throw e;
|
|
14139
14211
|
});
|
package/dist/esbuild.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
|
});
|