unplugin-https-reverse-proxy 4.1.0-beta.3 → 4.1.0-beta.5
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/{chunk-HBXMM25C.js → chunk-A3KSOGWY.js} +272 -652
- package/dist/esbuild.cjs +275 -655
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +275 -655
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +273 -653
- package/dist/nuxt.js +1 -1
- package/dist/privileged-helper.cjs +110 -13
- package/dist/privileged-helper.js +111 -14
- package/dist/rollup.cjs +275 -655
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +275 -655
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +275 -655
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +275 -655
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/config.ts +176 -57
- package/src/caddy/index.ts +82 -125
- package/src/privileged/bootstrap.ts +83 -2
- package/src/privileged/launch.ts +46 -9
- package/src/privileged/server.ts +95 -14
- package/src/privileged/session.ts +63 -14
package/dist/rspack.cjs
CHANGED
|
@@ -35,7 +35,7 @@ __export(rspack_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(rspack_exports);
|
|
36
36
|
|
|
37
37
|
// src/index.ts
|
|
38
|
-
var
|
|
38
|
+
var import_node_process9 = __toESM(require("process"), 1);
|
|
39
39
|
var import_console_table_printer = require("console-table-printer");
|
|
40
40
|
var import_picocolors2 = __toESM(require("picocolors"), 1);
|
|
41
41
|
var import_unplugin = require("unplugin");
|
|
@@ -43,450 +43,13 @@ var import_unplugin = require("unplugin");
|
|
|
43
43
|
// src/caddy/index.ts
|
|
44
44
|
var import_node_child_process3 = require("child_process");
|
|
45
45
|
var import_node_fs4 = require("fs");
|
|
46
|
-
var
|
|
46
|
+
var import_promises2 = require("fs/promises");
|
|
47
47
|
var import_node_os5 = require("os");
|
|
48
48
|
var import_node_path5 = require("path");
|
|
49
|
-
var
|
|
50
|
-
|
|
51
|
-
// node_modules/.pnpm/alien-signals@2.0.7/node_modules/alien-signals/esm/system.mjs
|
|
52
|
-
var ReactiveFlags;
|
|
53
|
-
(function(ReactiveFlags2) {
|
|
54
|
-
ReactiveFlags2[ReactiveFlags2["None"] = 0] = "None";
|
|
55
|
-
ReactiveFlags2[ReactiveFlags2["Mutable"] = 1] = "Mutable";
|
|
56
|
-
ReactiveFlags2[ReactiveFlags2["Watching"] = 2] = "Watching";
|
|
57
|
-
ReactiveFlags2[ReactiveFlags2["RecursedCheck"] = 4] = "RecursedCheck";
|
|
58
|
-
ReactiveFlags2[ReactiveFlags2["Recursed"] = 8] = "Recursed";
|
|
59
|
-
ReactiveFlags2[ReactiveFlags2["Dirty"] = 16] = "Dirty";
|
|
60
|
-
ReactiveFlags2[ReactiveFlags2["Pending"] = 32] = "Pending";
|
|
61
|
-
})(ReactiveFlags || (ReactiveFlags = {}));
|
|
62
|
-
function createReactiveSystem({ update, notify: notify2, unwatched }) {
|
|
63
|
-
let currentVersion = 0;
|
|
64
|
-
return {
|
|
65
|
-
link: link2,
|
|
66
|
-
unlink: unlink4,
|
|
67
|
-
propagate: propagate2,
|
|
68
|
-
checkDirty: checkDirty2,
|
|
69
|
-
endTracking: endTracking2,
|
|
70
|
-
startTracking: startTracking2,
|
|
71
|
-
shallowPropagate: shallowPropagate2
|
|
72
|
-
};
|
|
73
|
-
function link2(dep, sub) {
|
|
74
|
-
const prevDep = sub.depsTail;
|
|
75
|
-
if (prevDep !== void 0 && prevDep.dep === dep) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
79
|
-
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
80
|
-
nextDep.version = currentVersion;
|
|
81
|
-
sub.depsTail = nextDep;
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const prevSub = dep.subsTail;
|
|
85
|
-
if (prevSub !== void 0 && prevSub.version === currentVersion && prevSub.sub === sub) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
const newLink = sub.depsTail = dep.subsTail = {
|
|
89
|
-
version: currentVersion,
|
|
90
|
-
dep,
|
|
91
|
-
sub,
|
|
92
|
-
prevDep,
|
|
93
|
-
nextDep,
|
|
94
|
-
prevSub,
|
|
95
|
-
nextSub: void 0
|
|
96
|
-
};
|
|
97
|
-
if (nextDep !== void 0) {
|
|
98
|
-
nextDep.prevDep = newLink;
|
|
99
|
-
}
|
|
100
|
-
if (prevDep !== void 0) {
|
|
101
|
-
prevDep.nextDep = newLink;
|
|
102
|
-
} else {
|
|
103
|
-
sub.deps = newLink;
|
|
104
|
-
}
|
|
105
|
-
if (prevSub !== void 0) {
|
|
106
|
-
prevSub.nextSub = newLink;
|
|
107
|
-
} else {
|
|
108
|
-
dep.subs = newLink;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
function unlink4(link3, sub = link3.sub) {
|
|
112
|
-
const dep = link3.dep;
|
|
113
|
-
const prevDep = link3.prevDep;
|
|
114
|
-
const nextDep = link3.nextDep;
|
|
115
|
-
const nextSub = link3.nextSub;
|
|
116
|
-
const prevSub = link3.prevSub;
|
|
117
|
-
if (nextDep !== void 0) {
|
|
118
|
-
nextDep.prevDep = prevDep;
|
|
119
|
-
} else {
|
|
120
|
-
sub.depsTail = prevDep;
|
|
121
|
-
}
|
|
122
|
-
if (prevDep !== void 0) {
|
|
123
|
-
prevDep.nextDep = nextDep;
|
|
124
|
-
} else {
|
|
125
|
-
sub.deps = nextDep;
|
|
126
|
-
}
|
|
127
|
-
if (nextSub !== void 0) {
|
|
128
|
-
nextSub.prevSub = prevSub;
|
|
129
|
-
} else {
|
|
130
|
-
dep.subsTail = prevSub;
|
|
131
|
-
}
|
|
132
|
-
if (prevSub !== void 0) {
|
|
133
|
-
prevSub.nextSub = nextSub;
|
|
134
|
-
} else if ((dep.subs = nextSub) === void 0) {
|
|
135
|
-
unwatched(dep);
|
|
136
|
-
}
|
|
137
|
-
return nextDep;
|
|
138
|
-
}
|
|
139
|
-
function propagate2(link3) {
|
|
140
|
-
let next2 = link3.nextSub;
|
|
141
|
-
let stack;
|
|
142
|
-
top:
|
|
143
|
-
do {
|
|
144
|
-
const sub = link3.sub;
|
|
145
|
-
let flags = sub.flags;
|
|
146
|
-
if (!(flags & 60)) {
|
|
147
|
-
sub.flags = flags | 32;
|
|
148
|
-
} else if (!(flags & 12)) {
|
|
149
|
-
flags = 0;
|
|
150
|
-
} else if (!(flags & 4)) {
|
|
151
|
-
sub.flags = flags & ~8 | 32;
|
|
152
|
-
} else if (!(flags & 48) && isValidLink(link3, sub)) {
|
|
153
|
-
sub.flags = flags | 40;
|
|
154
|
-
flags &= 1;
|
|
155
|
-
} else {
|
|
156
|
-
flags = 0;
|
|
157
|
-
}
|
|
158
|
-
if (flags & 2) {
|
|
159
|
-
notify2(sub);
|
|
160
|
-
}
|
|
161
|
-
if (flags & 1) {
|
|
162
|
-
const subSubs = sub.subs;
|
|
163
|
-
if (subSubs !== void 0) {
|
|
164
|
-
const nextSub = (link3 = subSubs).nextSub;
|
|
165
|
-
if (nextSub !== void 0) {
|
|
166
|
-
stack = { value: next2, prev: stack };
|
|
167
|
-
next2 = nextSub;
|
|
168
|
-
}
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if ((link3 = next2) !== void 0) {
|
|
173
|
-
next2 = link3.nextSub;
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
while (stack !== void 0) {
|
|
177
|
-
link3 = stack.value;
|
|
178
|
-
stack = stack.prev;
|
|
179
|
-
if (link3 !== void 0) {
|
|
180
|
-
next2 = link3.nextSub;
|
|
181
|
-
continue top;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
} while (true);
|
|
186
|
-
}
|
|
187
|
-
function startTracking2(sub) {
|
|
188
|
-
++currentVersion;
|
|
189
|
-
sub.depsTail = void 0;
|
|
190
|
-
sub.flags = sub.flags & ~56 | 4;
|
|
191
|
-
}
|
|
192
|
-
function endTracking2(sub) {
|
|
193
|
-
const depsTail = sub.depsTail;
|
|
194
|
-
let toRemove = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
195
|
-
while (toRemove !== void 0) {
|
|
196
|
-
toRemove = unlink4(toRemove, sub);
|
|
197
|
-
}
|
|
198
|
-
sub.flags &= ~4;
|
|
199
|
-
}
|
|
200
|
-
function checkDirty2(link3, sub) {
|
|
201
|
-
let stack;
|
|
202
|
-
let checkDepth = 0;
|
|
203
|
-
top:
|
|
204
|
-
do {
|
|
205
|
-
const dep = link3.dep;
|
|
206
|
-
const flags = dep.flags;
|
|
207
|
-
let dirty = false;
|
|
208
|
-
if (sub.flags & 16) {
|
|
209
|
-
dirty = true;
|
|
210
|
-
} else if ((flags & 17) === 17) {
|
|
211
|
-
if (update(dep)) {
|
|
212
|
-
const subs = dep.subs;
|
|
213
|
-
if (subs.nextSub !== void 0) {
|
|
214
|
-
shallowPropagate2(subs);
|
|
215
|
-
}
|
|
216
|
-
dirty = true;
|
|
217
|
-
}
|
|
218
|
-
} else if ((flags & 33) === 33) {
|
|
219
|
-
if (link3.nextSub !== void 0 || link3.prevSub !== void 0) {
|
|
220
|
-
stack = { value: link3, prev: stack };
|
|
221
|
-
}
|
|
222
|
-
link3 = dep.deps;
|
|
223
|
-
sub = dep;
|
|
224
|
-
++checkDepth;
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
if (!dirty) {
|
|
228
|
-
const nextDep = link3.nextDep;
|
|
229
|
-
if (nextDep !== void 0) {
|
|
230
|
-
link3 = nextDep;
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
while (checkDepth--) {
|
|
235
|
-
const firstSub = sub.subs;
|
|
236
|
-
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
237
|
-
if (hasMultipleSubs) {
|
|
238
|
-
link3 = stack.value;
|
|
239
|
-
stack = stack.prev;
|
|
240
|
-
} else {
|
|
241
|
-
link3 = firstSub;
|
|
242
|
-
}
|
|
243
|
-
if (dirty) {
|
|
244
|
-
if (update(sub)) {
|
|
245
|
-
if (hasMultipleSubs) {
|
|
246
|
-
shallowPropagate2(firstSub);
|
|
247
|
-
}
|
|
248
|
-
sub = link3.sub;
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
sub.flags &= ~32;
|
|
253
|
-
}
|
|
254
|
-
sub = link3.sub;
|
|
255
|
-
const nextDep = link3.nextDep;
|
|
256
|
-
if (nextDep !== void 0) {
|
|
257
|
-
link3 = nextDep;
|
|
258
|
-
continue top;
|
|
259
|
-
}
|
|
260
|
-
dirty = false;
|
|
261
|
-
}
|
|
262
|
-
return dirty;
|
|
263
|
-
} while (true);
|
|
264
|
-
}
|
|
265
|
-
function shallowPropagate2(link3) {
|
|
266
|
-
do {
|
|
267
|
-
const sub = link3.sub;
|
|
268
|
-
const flags = sub.flags;
|
|
269
|
-
if ((flags & 48) === 32) {
|
|
270
|
-
sub.flags = flags | 16;
|
|
271
|
-
if (flags & 2) {
|
|
272
|
-
notify2(sub);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
} while ((link3 = link3.nextSub) !== void 0);
|
|
276
|
-
}
|
|
277
|
-
function isValidLink(checkLink, sub) {
|
|
278
|
-
let link3 = sub.depsTail;
|
|
279
|
-
while (link3 !== void 0) {
|
|
280
|
-
if (link3 === checkLink) {
|
|
281
|
-
return true;
|
|
282
|
-
}
|
|
283
|
-
link3 = link3.prevDep;
|
|
284
|
-
}
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// node_modules/.pnpm/alien-signals@2.0.7/node_modules/alien-signals/esm/index.mjs
|
|
290
|
-
var queuedEffects = [];
|
|
291
|
-
var { link, unlink, propagate, checkDirty, endTracking, startTracking, shallowPropagate } = createReactiveSystem({
|
|
292
|
-
update(signal2) {
|
|
293
|
-
if ("getter" in signal2) {
|
|
294
|
-
return updateComputed(signal2);
|
|
295
|
-
} else {
|
|
296
|
-
return updateSignal(signal2, signal2.value);
|
|
297
|
-
}
|
|
298
|
-
},
|
|
299
|
-
notify,
|
|
300
|
-
unwatched(node2) {
|
|
301
|
-
if ("getter" in node2) {
|
|
302
|
-
let toRemove = node2.deps;
|
|
303
|
-
if (toRemove !== void 0) {
|
|
304
|
-
node2.flags = 17;
|
|
305
|
-
do {
|
|
306
|
-
toRemove = unlink(toRemove, node2);
|
|
307
|
-
} while (toRemove !== void 0);
|
|
308
|
-
}
|
|
309
|
-
} else if (!("previousValue" in node2)) {
|
|
310
|
-
effectOper.call(node2);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
var batchDepth = 0;
|
|
315
|
-
var notifyIndex = 0;
|
|
316
|
-
var queuedEffectsLength = 0;
|
|
317
|
-
var activeSub;
|
|
318
|
-
var activeScope;
|
|
319
|
-
function setCurrentSub(sub) {
|
|
320
|
-
const prevSub = activeSub;
|
|
321
|
-
activeSub = sub;
|
|
322
|
-
return prevSub;
|
|
323
|
-
}
|
|
324
|
-
function signal(initialValue) {
|
|
325
|
-
return signalOper.bind({
|
|
326
|
-
previousValue: initialValue,
|
|
327
|
-
value: initialValue,
|
|
328
|
-
subs: void 0,
|
|
329
|
-
subsTail: void 0,
|
|
330
|
-
flags: 1
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
function computed(getter) {
|
|
334
|
-
return computedOper.bind({
|
|
335
|
-
value: void 0,
|
|
336
|
-
subs: void 0,
|
|
337
|
-
subsTail: void 0,
|
|
338
|
-
deps: void 0,
|
|
339
|
-
depsTail: void 0,
|
|
340
|
-
flags: 17,
|
|
341
|
-
getter
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
function effect(fn) {
|
|
345
|
-
const e = {
|
|
346
|
-
fn,
|
|
347
|
-
subs: void 0,
|
|
348
|
-
subsTail: void 0,
|
|
349
|
-
deps: void 0,
|
|
350
|
-
depsTail: void 0,
|
|
351
|
-
flags: 2
|
|
352
|
-
};
|
|
353
|
-
if (activeSub !== void 0) {
|
|
354
|
-
link(e, activeSub);
|
|
355
|
-
} else if (activeScope !== void 0) {
|
|
356
|
-
link(e, activeScope);
|
|
357
|
-
}
|
|
358
|
-
const prev = setCurrentSub(e);
|
|
359
|
-
try {
|
|
360
|
-
e.fn();
|
|
361
|
-
} finally {
|
|
362
|
-
setCurrentSub(prev);
|
|
363
|
-
}
|
|
364
|
-
return effectOper.bind(e);
|
|
365
|
-
}
|
|
366
|
-
function updateComputed(c3) {
|
|
367
|
-
const prevSub = setCurrentSub(c3);
|
|
368
|
-
startTracking(c3);
|
|
369
|
-
try {
|
|
370
|
-
const oldValue = c3.value;
|
|
371
|
-
return oldValue !== (c3.value = c3.getter(oldValue));
|
|
372
|
-
} finally {
|
|
373
|
-
setCurrentSub(prevSub);
|
|
374
|
-
endTracking(c3);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
function updateSignal(s, value2) {
|
|
378
|
-
s.flags = 1;
|
|
379
|
-
return s.previousValue !== (s.previousValue = value2);
|
|
380
|
-
}
|
|
381
|
-
function notify(e) {
|
|
382
|
-
const flags = e.flags;
|
|
383
|
-
if (!(flags & 64)) {
|
|
384
|
-
e.flags = flags | 64;
|
|
385
|
-
const subs = e.subs;
|
|
386
|
-
if (subs !== void 0) {
|
|
387
|
-
notify(subs.sub);
|
|
388
|
-
} else {
|
|
389
|
-
queuedEffects[queuedEffectsLength++] = e;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
function run(e, flags) {
|
|
394
|
-
if (flags & 16 || flags & 32 && checkDirty(e.deps, e)) {
|
|
395
|
-
const prev = setCurrentSub(e);
|
|
396
|
-
startTracking(e);
|
|
397
|
-
try {
|
|
398
|
-
e.fn();
|
|
399
|
-
} finally {
|
|
400
|
-
setCurrentSub(prev);
|
|
401
|
-
endTracking(e);
|
|
402
|
-
}
|
|
403
|
-
return;
|
|
404
|
-
} else if (flags & 32) {
|
|
405
|
-
e.flags = flags & ~32;
|
|
406
|
-
}
|
|
407
|
-
let link2 = e.deps;
|
|
408
|
-
while (link2 !== void 0) {
|
|
409
|
-
const dep = link2.dep;
|
|
410
|
-
const depFlags = dep.flags;
|
|
411
|
-
if (depFlags & 64) {
|
|
412
|
-
run(dep, dep.flags = depFlags & ~64);
|
|
413
|
-
}
|
|
414
|
-
link2 = link2.nextDep;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
function flush() {
|
|
418
|
-
while (notifyIndex < queuedEffectsLength) {
|
|
419
|
-
const effect2 = queuedEffects[notifyIndex];
|
|
420
|
-
queuedEffects[notifyIndex++] = void 0;
|
|
421
|
-
run(effect2, effect2.flags &= ~64);
|
|
422
|
-
}
|
|
423
|
-
notifyIndex = 0;
|
|
424
|
-
queuedEffectsLength = 0;
|
|
425
|
-
}
|
|
426
|
-
function computedOper() {
|
|
427
|
-
const flags = this.flags;
|
|
428
|
-
if (flags & 16 || flags & 32 && checkDirty(this.deps, this)) {
|
|
429
|
-
if (updateComputed(this)) {
|
|
430
|
-
const subs = this.subs;
|
|
431
|
-
if (subs !== void 0) {
|
|
432
|
-
shallowPropagate(subs);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
} else if (flags & 32) {
|
|
436
|
-
this.flags = flags & ~32;
|
|
437
|
-
}
|
|
438
|
-
if (activeSub !== void 0) {
|
|
439
|
-
link(this, activeSub);
|
|
440
|
-
} else if (activeScope !== void 0) {
|
|
441
|
-
link(this, activeScope);
|
|
442
|
-
}
|
|
443
|
-
return this.value;
|
|
444
|
-
}
|
|
445
|
-
function signalOper(...value2) {
|
|
446
|
-
if (value2.length) {
|
|
447
|
-
if (this.value !== (this.value = value2[0])) {
|
|
448
|
-
this.flags = 17;
|
|
449
|
-
const subs = this.subs;
|
|
450
|
-
if (subs !== void 0) {
|
|
451
|
-
propagate(subs);
|
|
452
|
-
if (!batchDepth) {
|
|
453
|
-
flush();
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
} else {
|
|
458
|
-
const value3 = this.value;
|
|
459
|
-
if (this.flags & 16) {
|
|
460
|
-
if (updateSignal(this, value3)) {
|
|
461
|
-
const subs = this.subs;
|
|
462
|
-
if (subs !== void 0) {
|
|
463
|
-
shallowPropagate(subs);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (activeSub !== void 0) {
|
|
468
|
-
link(this, activeSub);
|
|
469
|
-
}
|
|
470
|
-
return value3;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
function effectOper() {
|
|
474
|
-
let dep = this.deps;
|
|
475
|
-
while (dep !== void 0) {
|
|
476
|
-
dep = unlink(dep, this);
|
|
477
|
-
}
|
|
478
|
-
const sub = this.subs;
|
|
479
|
-
if (sub !== void 0) {
|
|
480
|
-
unlink(sub);
|
|
481
|
-
}
|
|
482
|
-
this.flags = 0;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// src/caddy/index.ts
|
|
49
|
+
var import_node_process8 = __toESM(require("process"), 1);
|
|
486
50
|
var import_got_cjs = require("got-cjs");
|
|
487
51
|
var import_http_proxy_agent = require("http-proxy-agent");
|
|
488
52
|
var import_https_proxy_agent = require("https-proxy-agent");
|
|
489
|
-
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
490
53
|
|
|
491
54
|
// src/utils.ts
|
|
492
55
|
var import_node_os = require("os");
|
|
@@ -13468,7 +13031,8 @@ async function genCaddyfile(ctx) {
|
|
|
13468
13031
|
|
|
13469
13032
|
// src/caddy/config.ts
|
|
13470
13033
|
var import_node_fs = require("fs");
|
|
13471
|
-
var
|
|
13034
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
|
13035
|
+
var lockfile = __toESM(require("proper-lockfile"), 1);
|
|
13472
13036
|
|
|
13473
13037
|
// src/caddy/constants.ts
|
|
13474
13038
|
var import_node_os2 = __toESM(require("os"), 1);
|
|
@@ -13600,56 +13164,108 @@ var supportList = [
|
|
|
13600
13164
|
];
|
|
13601
13165
|
|
|
13602
13166
|
// src/caddy/config.ts
|
|
13603
|
-
function
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
});
|
|
13612
|
-
function setConfigContent() {
|
|
13613
|
-
if (!(0, import_node_fs.existsSync)(caddyConfigPath)) {
|
|
13614
|
-
(0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
|
|
13615
|
-
}
|
|
13616
|
-
try {
|
|
13617
|
-
configContentRef((0, import_node_fs.readFileSync)(caddyConfigPath, "utf-8"));
|
|
13618
|
-
} catch {
|
|
13619
|
-
configContentRef("");
|
|
13620
|
-
}
|
|
13167
|
+
function isAlive(pid) {
|
|
13168
|
+
if (pid === void 0)
|
|
13169
|
+
return true;
|
|
13170
|
+
try {
|
|
13171
|
+
import_node_process2.default.kill(pid, 0);
|
|
13172
|
+
return true;
|
|
13173
|
+
} catch {
|
|
13174
|
+
return false;
|
|
13621
13175
|
}
|
|
13622
|
-
|
|
13623
|
-
|
|
13176
|
+
}
|
|
13177
|
+
function readConfig() {
|
|
13178
|
+
if (!(0, import_node_fs.existsSync)(caddyConfigPath))
|
|
13179
|
+
return {};
|
|
13180
|
+
let parsed2;
|
|
13181
|
+
try {
|
|
13182
|
+
parsed2 = JSON.parse((0, import_node_fs.readFileSync)(caddyConfigPath, "utf-8"));
|
|
13183
|
+
} catch {
|
|
13184
|
+
return {};
|
|
13624
13185
|
}
|
|
13625
|
-
const
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
const proxies = configJsonRef() || {};
|
|
13630
|
-
_proxies.forEach((p) => {
|
|
13631
|
-
let base = p.base || "/";
|
|
13632
|
-
if (!base.startsWith("/"))
|
|
13633
|
-
base = `/${base}`;
|
|
13634
|
-
if (base !== "/" && !base.endsWith("/"))
|
|
13635
|
-
base = `${base}/`;
|
|
13636
|
-
const index = `${p.target}${p.portSuffix}${base}`;
|
|
13637
|
-
proxies[index] = { ...p, base };
|
|
13638
|
-
});
|
|
13639
|
-
const content = JSON.stringify(proxies, null, 2);
|
|
13640
|
-
configContentRef(content);
|
|
13641
|
-
return (0, import_node_fs.writeFileSync)(caddyConfigPath, content);
|
|
13186
|
+
const alive = {};
|
|
13187
|
+
for (const [key, entry] of Object.entries(parsed2)) {
|
|
13188
|
+
if (isAlive(entry == null ? void 0 : entry.ownerPid))
|
|
13189
|
+
alive[key] = entry;
|
|
13642
13190
|
}
|
|
13643
|
-
|
|
13644
|
-
|
|
13645
|
-
|
|
13646
|
-
|
|
13647
|
-
|
|
13191
|
+
return alive;
|
|
13192
|
+
}
|
|
13193
|
+
function writeConfig(proxies) {
|
|
13194
|
+
const content = JSON.stringify(proxies, null, 2);
|
|
13195
|
+
const temp = `${caddyConfigPath}.${import_node_process2.default.pid}.tmp`;
|
|
13196
|
+
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13197
|
+
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13198
|
+
}
|
|
13199
|
+
async function mutateConfig(lock3, mutate) {
|
|
13200
|
+
const release = await lock3.acquire();
|
|
13201
|
+
try {
|
|
13202
|
+
const proxies = readConfig();
|
|
13203
|
+
mutate(proxies);
|
|
13204
|
+
writeConfig(proxies);
|
|
13205
|
+
return proxies;
|
|
13206
|
+
} finally {
|
|
13207
|
+
release();
|
|
13648
13208
|
}
|
|
13209
|
+
}
|
|
13210
|
+
function useCaddyConfig(options = {}) {
|
|
13211
|
+
const lock3 = options.lock ?? createFileLock();
|
|
13649
13212
|
return {
|
|
13650
|
-
configJsonRef,
|
|
13651
|
-
writeCaddyConfig,
|
|
13652
|
-
|
|
13213
|
+
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13214
|
+
async writeCaddyConfig(_proxies, key) {
|
|
13215
|
+
await mutateConfig(lock3, (proxies) => {
|
|
13216
|
+
for (const p of _proxies)
|
|
13217
|
+
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13218
|
+
});
|
|
13219
|
+
},
|
|
13220
|
+
async removeProxy(key) {
|
|
13221
|
+
const proxies = await mutateConfig(lock3, (current) => {
|
|
13222
|
+
for (const route of Object.keys(current)) {
|
|
13223
|
+
if (route.endsWith(`#${key}`))
|
|
13224
|
+
delete current[route];
|
|
13225
|
+
}
|
|
13226
|
+
});
|
|
13227
|
+
if (Object.keys(proxies).length === 0)
|
|
13228
|
+
removeConfigFile();
|
|
13229
|
+
},
|
|
13230
|
+
readProxies: () => readConfig(),
|
|
13231
|
+
async cleanUp() {
|
|
13232
|
+
removeConfigFile();
|
|
13233
|
+
}
|
|
13234
|
+
};
|
|
13235
|
+
}
|
|
13236
|
+
function removeConfigFile() {
|
|
13237
|
+
try {
|
|
13238
|
+
if ((0, import_node_fs.existsSync)(caddyConfigPath))
|
|
13239
|
+
(0, import_node_fs.unlinkSync)(caddyConfigPath);
|
|
13240
|
+
} catch {
|
|
13241
|
+
}
|
|
13242
|
+
}
|
|
13243
|
+
function normalizeBase(base) {
|
|
13244
|
+
let out = base || "/";
|
|
13245
|
+
if (!out.startsWith("/"))
|
|
13246
|
+
out = `/${out}`;
|
|
13247
|
+
if (out !== "/" && !out.endsWith("/"))
|
|
13248
|
+
out = `${out}/`;
|
|
13249
|
+
return out;
|
|
13250
|
+
}
|
|
13251
|
+
function routeKey(proxy, ownerKey) {
|
|
13252
|
+
return `${proxy.target}${proxy.portSuffix}${normalizeBase(proxy.base)}#${ownerKey}`;
|
|
13253
|
+
}
|
|
13254
|
+
function createFileLock() {
|
|
13255
|
+
return {
|
|
13256
|
+
async acquire() {
|
|
13257
|
+
if (!(0, import_node_fs.existsSync)(caddyConfigPath))
|
|
13258
|
+
(0, import_node_fs.writeFileSync)(caddyConfigPath, "{}");
|
|
13259
|
+
const release = await lockfile.lock(caddyConfigPath, {
|
|
13260
|
+
realpath: false,
|
|
13261
|
+
stale: 1e4,
|
|
13262
|
+
retries: { retries: 20, minTimeout: 10, maxTimeout: 100 }
|
|
13263
|
+
});
|
|
13264
|
+
return () => {
|
|
13265
|
+
void release().catch(() => {
|
|
13266
|
+
});
|
|
13267
|
+
};
|
|
13268
|
+
}
|
|
13653
13269
|
};
|
|
13654
13270
|
}
|
|
13655
13271
|
|
|
@@ -13667,15 +13283,15 @@ function isCaddyReloadCancellation(line) {
|
|
|
13667
13283
|
var import_node_buffer2 = require("buffer");
|
|
13668
13284
|
var import_node_events = require("events");
|
|
13669
13285
|
var import_node_path4 = require("path");
|
|
13670
|
-
var
|
|
13286
|
+
var import_node_process7 = __toESM(require("process"), 1);
|
|
13671
13287
|
var import_node_url = require("url");
|
|
13672
13288
|
|
|
13673
13289
|
// src/privileged/entry.ts
|
|
13674
13290
|
var import_node_fs2 = require("fs");
|
|
13675
13291
|
var import_node_path2 = require("path");
|
|
13676
|
-
var
|
|
13292
|
+
var import_node_process3 = __toESM(require("process"), 1);
|
|
13677
13293
|
function resolveHelperEntry(options) {
|
|
13678
|
-
const { moduleDir, nodeBin =
|
|
13294
|
+
const { moduleDir, nodeBin = import_node_process3.default.execPath, exists: exists2 = import_node_fs2.existsSync } = options;
|
|
13679
13295
|
for (const name of ["privileged-helper.js", "privileged-helper.cjs", "privileged-helper.mjs"]) {
|
|
13680
13296
|
const candidate = findUp(moduleDir, name, exists2);
|
|
13681
13297
|
if (candidate)
|
|
@@ -13703,19 +13319,20 @@ function findUp(from, relative, exists2) {
|
|
|
13703
13319
|
// src/privileged/session.ts
|
|
13704
13320
|
var import_node_buffer = require("buffer");
|
|
13705
13321
|
var import_node_fs3 = require("fs");
|
|
13706
|
-
var
|
|
13322
|
+
var import_promises = require("fs/promises");
|
|
13707
13323
|
var import_node_os4 = require("os");
|
|
13708
13324
|
var import_node_path3 = require("path");
|
|
13325
|
+
var lockfile2 = __toESM(require("proper-lockfile"), 1);
|
|
13709
13326
|
|
|
13710
13327
|
// src/privileged/launch.ts
|
|
13711
13328
|
var import_node_child_process2 = require("child_process");
|
|
13712
13329
|
var import_node_crypto = require("crypto");
|
|
13713
13330
|
var import_node_os3 = require("os");
|
|
13714
|
-
var
|
|
13331
|
+
var import_node_process6 = __toESM(require("process"), 1);
|
|
13715
13332
|
|
|
13716
13333
|
// src/privileged/client.ts
|
|
13717
13334
|
var import_node_net = require("net");
|
|
13718
|
-
var
|
|
13335
|
+
var import_node_process4 = __toESM(require("process"), 1);
|
|
13719
13336
|
|
|
13720
13337
|
// src/privileged/protocol.ts
|
|
13721
13338
|
function serializeMessage(message) {
|
|
@@ -13778,7 +13395,7 @@ var FORWARDED_ENV_KEYS = [
|
|
|
13778
13395
|
"NO_PROXY",
|
|
13779
13396
|
"no_proxy"
|
|
13780
13397
|
];
|
|
13781
|
-
function collectForwardedEnv(source =
|
|
13398
|
+
function collectForwardedEnv(source = import_node_process4.default.env) {
|
|
13782
13399
|
const result = {};
|
|
13783
13400
|
for (const key of FORWARDED_ENV_KEYS) {
|
|
13784
13401
|
const value2 = source[key];
|
|
@@ -13955,7 +13572,7 @@ function createClient(socket, initialBuffer, callTimeoutMs) {
|
|
|
13955
13572
|
|
|
13956
13573
|
// src/privileged/windows-elevation.ts
|
|
13957
13574
|
var import_node_child_process = require("child_process");
|
|
13958
|
-
var
|
|
13575
|
+
var import_node_process5 = __toESM(require("process"), 1);
|
|
13959
13576
|
function quotePowerShell(value2) {
|
|
13960
13577
|
return `'${value2.replace(/'/g, "''")}'`;
|
|
13961
13578
|
}
|
|
@@ -14008,24 +13625,42 @@ function describePasswordReason(target, https) {
|
|
|
14008
13625
|
"Press Ctrl+C at the prompt to skip the proxy and keep the dev server."
|
|
14009
13626
|
];
|
|
14010
13627
|
}
|
|
14011
|
-
function authenticateSudo(sudoCommand = "sudo", options = {}) {
|
|
13628
|
+
async function authenticateSudo(sudoCommand = "sudo", options = {}) {
|
|
14012
13629
|
if ((0, import_node_os3.platform)() === "win32")
|
|
14013
13630
|
return { ok: true };
|
|
14014
13631
|
if ((0, import_node_child_process2.spawnSync)(sudoCommand, ["-n", "true"], { stdio: "ignore" }).status === 0)
|
|
14015
13632
|
return { ok: true };
|
|
14016
13633
|
if (options.target) {
|
|
14017
13634
|
for (const line of describePasswordReason(options.target, options.https ?? false))
|
|
14018
|
-
|
|
13635
|
+
import_node_process6.default.stderr.write(`${line}
|
|
14019
13636
|
`);
|
|
14020
|
-
|
|
13637
|
+
import_node_process6.default.stderr.write("\n");
|
|
14021
13638
|
}
|
|
14022
|
-
|
|
14023
|
-
|
|
14024
|
-
|
|
14025
|
-
ok: false,
|
|
14026
|
-
denied: true,
|
|
14027
|
-
message: "administrator permission is required to edit the hosts file and bind ports 80/443"
|
|
13639
|
+
let interrupted = false;
|
|
13640
|
+
const onSigint = () => {
|
|
13641
|
+
interrupted = true;
|
|
14028
13642
|
};
|
|
13643
|
+
import_node_process6.default.on("SIGINT", onSigint);
|
|
13644
|
+
try {
|
|
13645
|
+
const { status, signal } = await runPrompt(sudoCommand);
|
|
13646
|
+
if (status === 0)
|
|
13647
|
+
return { ok: true };
|
|
13648
|
+
const cancelled = interrupted || signal === "SIGINT";
|
|
13649
|
+
return {
|
|
13650
|
+
ok: false,
|
|
13651
|
+
denied: true,
|
|
13652
|
+
message: cancelled ? "administrator permission was cancelled" : "administrator permission is required to edit the hosts file and bind ports 80/443"
|
|
13653
|
+
};
|
|
13654
|
+
} finally {
|
|
13655
|
+
import_node_process6.default.off("SIGINT", onSigint);
|
|
13656
|
+
}
|
|
13657
|
+
}
|
|
13658
|
+
function runPrompt(sudoCommand) {
|
|
13659
|
+
return new Promise((resolve2) => {
|
|
13660
|
+
const child = (0, import_node_child_process2.spawn)(sudoCommand, ["-v"], { stdio: "inherit" });
|
|
13661
|
+
child.on("error", () => resolve2({ status: 1, signal: null }));
|
|
13662
|
+
child.on("exit", (status, signal) => resolve2({ status, signal }));
|
|
13663
|
+
});
|
|
14029
13664
|
}
|
|
14030
13665
|
var PrivilegeDeniedError = class extends Error {
|
|
14031
13666
|
constructor(message) {
|
|
@@ -14043,12 +13678,12 @@ async function startPrivilegedHelper(options) {
|
|
|
14043
13678
|
sudoCommand = "sudo",
|
|
14044
13679
|
skipAuth = false,
|
|
14045
13680
|
direct = false,
|
|
14046
|
-
env: env2 =
|
|
13681
|
+
env: env2 = import_node_process6.default.env,
|
|
14047
13682
|
log,
|
|
14048
13683
|
connectTimeoutMs = 12e4
|
|
14049
13684
|
} = options;
|
|
14050
13685
|
if (!skipAuth && !direct) {
|
|
14051
|
-
const auth = authenticateSudo(sudoCommand, options.reason);
|
|
13686
|
+
const auth = await authenticateSudo(sudoCommand, options.reason);
|
|
14052
13687
|
if (!auth.ok) {
|
|
14053
13688
|
const message = auth.message ?? "administrator permission is required";
|
|
14054
13689
|
throw auth.denied ? new PrivilegeDeniedError(message) : new Error(message);
|
|
@@ -14062,8 +13697,8 @@ async function startPrivilegedHelper(options) {
|
|
|
14062
13697
|
socketPath,
|
|
14063
13698
|
"--token",
|
|
14064
13699
|
token,
|
|
14065
|
-
...typeof
|
|
14066
|
-
...typeof
|
|
13700
|
+
...typeof import_node_process6.default.getuid === "function" ? ["--owner-uid", String(import_node_process6.default.getuid())] : [],
|
|
13701
|
+
...typeof import_node_process6.default.getgid === "function" ? ["--owner-gid", String(import_node_process6.default.getgid())] : [],
|
|
14067
13702
|
...options.caddyStoragePath ? ["--caddy-storage", options.caddyStoragePath] : [],
|
|
14068
13703
|
"--caddy",
|
|
14069
13704
|
options.caddyBin,
|
|
@@ -14072,7 +13707,7 @@ async function startPrivilegedHelper(options) {
|
|
|
14072
13707
|
];
|
|
14073
13708
|
let child;
|
|
14074
13709
|
if (!direct && (0, import_node_os3.platform)() === "win32") {
|
|
14075
|
-
await spawnElevatedOnWindows({ file: helperEntry, args: childArgv, cwd:
|
|
13710
|
+
await spawnElevatedOnWindows({ file: helperEntry, args: childArgv, cwd: import_node_process6.default.cwd() });
|
|
14076
13711
|
} else {
|
|
14077
13712
|
const command = direct ? helperEntry : sudoCommand;
|
|
14078
13713
|
const spawnArgs = direct ? childArgv : ["-n", "env", ...forwardedArgs, helperEntry, ...childArgv];
|
|
@@ -14129,21 +13764,34 @@ function sessionSocketPath(runtimeDir) {
|
|
|
14129
13764
|
}
|
|
14130
13765
|
async function openHelperSession(scope2) {
|
|
14131
13766
|
const socketPath = sessionSocketPath(scope2.runtimeDir);
|
|
14132
|
-
|
|
14133
|
-
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
-
|
|
14137
|
-
|
|
14138
|
-
|
|
14139
|
-
|
|
14140
|
-
close: async () => {
|
|
14141
|
-
await reused.close();
|
|
14142
|
-
}
|
|
14143
|
-
};
|
|
14144
|
-
}
|
|
14145
|
-
}
|
|
13767
|
+
const release = await acquireStartLock(scope2.runtimeDir);
|
|
13768
|
+
try {
|
|
13769
|
+
const reused = await tryReuse(socketPath, scope2);
|
|
13770
|
+
if (reused)
|
|
13771
|
+
return reused;
|
|
13772
|
+
return await startNew(socketPath, scope2);
|
|
13773
|
+
} finally {
|
|
13774
|
+
release();
|
|
14146
13775
|
}
|
|
13776
|
+
}
|
|
13777
|
+
async function tryReuse(socketPath, scope2) {
|
|
13778
|
+
if (!(0, import_node_fs3.existsSync)(socketPath) && (0, import_node_os4.platform)() !== "win32")
|
|
13779
|
+
return void 0;
|
|
13780
|
+
const token = await readToken(scope2.runtimeDir);
|
|
13781
|
+
if (!token)
|
|
13782
|
+
return void 0;
|
|
13783
|
+
const reused = await connectExistingHelper(socketPath, token);
|
|
13784
|
+
if (!reused)
|
|
13785
|
+
return void 0;
|
|
13786
|
+
return {
|
|
13787
|
+
client: reused,
|
|
13788
|
+
reused: true,
|
|
13789
|
+
close: async () => {
|
|
13790
|
+
await reused.close();
|
|
13791
|
+
}
|
|
13792
|
+
};
|
|
13793
|
+
}
|
|
13794
|
+
async function startNew(socketPath, scope2) {
|
|
14147
13795
|
const token = createHelperToken();
|
|
14148
13796
|
const started = await startPrivilegedHelper({
|
|
14149
13797
|
socketPath,
|
|
@@ -14169,9 +13817,25 @@ async function openHelperSession(scope2) {
|
|
|
14169
13817
|
}
|
|
14170
13818
|
};
|
|
14171
13819
|
}
|
|
13820
|
+
async function acquireStartLock(runtimeDir) {
|
|
13821
|
+
const lockPath = (0, import_node_path3.join)(runtimeDir, "helper.start.lock");
|
|
13822
|
+
try {
|
|
13823
|
+
await (0, import_promises.writeFile)(lockPath, "", { flag: "a" });
|
|
13824
|
+
} catch {
|
|
13825
|
+
}
|
|
13826
|
+
const release = await lockfile2.lock(lockPath, {
|
|
13827
|
+
realpath: false,
|
|
13828
|
+
stale: 3e4,
|
|
13829
|
+
retries: { retries: 100, minTimeout: 50, maxTimeout: 200 }
|
|
13830
|
+
});
|
|
13831
|
+
return () => {
|
|
13832
|
+
void release().catch(() => {
|
|
13833
|
+
});
|
|
13834
|
+
};
|
|
13835
|
+
}
|
|
14172
13836
|
async function readToken(runtimeDir) {
|
|
14173
13837
|
try {
|
|
14174
|
-
const content = await (0,
|
|
13838
|
+
const content = await (0, import_promises.readFile)(tokenPath(runtimeDir), "utf8");
|
|
14175
13839
|
const token = content.trim();
|
|
14176
13840
|
return token === "" ? void 0 : token;
|
|
14177
13841
|
} catch {
|
|
@@ -14180,7 +13844,7 @@ async function readToken(runtimeDir) {
|
|
|
14180
13844
|
}
|
|
14181
13845
|
async function writeToken(runtimeDir, token) {
|
|
14182
13846
|
try {
|
|
14183
|
-
await (0,
|
|
13847
|
+
await (0, import_promises.writeFile)(tokenPath(runtimeDir), token, { mode: 384 });
|
|
14184
13848
|
} catch {
|
|
14185
13849
|
}
|
|
14186
13850
|
}
|
|
@@ -14228,7 +13892,7 @@ var HelperCaddyProcess = class extends import_node_events.EventEmitter {
|
|
|
14228
13892
|
}
|
|
14229
13893
|
};
|
|
14230
13894
|
function caddyStoragePath() {
|
|
14231
|
-
return
|
|
13895
|
+
return import_node_process7.default.platform === "win32" ? (0, import_node_path4.join)(import_node_process7.default.env.AppData ?? "", "Caddy") : (0, import_node_path4.join)(import_node_process7.default.env.HOME ?? "", "Library/Application Support/Caddy");
|
|
14232
13896
|
}
|
|
14233
13897
|
function openPrivilegedSession(runtimeDir, options) {
|
|
14234
13898
|
const env2 = resolvePrivilegedEnv();
|
|
@@ -14378,15 +14042,15 @@ async function download() {
|
|
|
14378
14042
|
const file = (0, import_node_fs4.createWriteStream)(caddyPath);
|
|
14379
14043
|
let _platform = (0, import_node_os5.platform)().toString();
|
|
14380
14044
|
_platform === "win32" && (_platform = "windows");
|
|
14381
|
-
let _arch =
|
|
14045
|
+
let _arch = import_node_process8.default.arch.toString();
|
|
14382
14046
|
_arch === "x64" && (_arch = "amd64");
|
|
14383
14047
|
const support = supportList.find((item) => item.platform === _platform && item.arch === _arch);
|
|
14384
14048
|
if (!support)
|
|
14385
14049
|
return reject2(new Error("not support"));
|
|
14386
14050
|
const dowmloadLink = `https://caddyserver.com/api/download?os=${support.platform}&arch=${support.arch}&p=github.com%2Fcaddyserver%2Fforwardproxy`;
|
|
14387
14051
|
(0, import_node_fs4.existsSync)(caddyPath) && (0, import_node_fs4.unlinkSync)(caddyPath);
|
|
14388
|
-
const httpProxy =
|
|
14389
|
-
const httpsProxy =
|
|
14052
|
+
const httpProxy = import_node_process8.default.env.HTTP_PROXY || import_node_process8.default.env.http_proxy;
|
|
14053
|
+
const httpsProxy = import_node_process8.default.env.HTTPS_PROXY || import_node_process8.default.env.https_proxy;
|
|
14390
14054
|
const httpAgent = httpProxy ? new import_http_proxy_agent.HttpProxyAgent(httpProxy) : void 0;
|
|
14391
14055
|
const httpsAgent = httpsProxy ? new import_https_proxy_agent.HttpsProxyAgent(httpsProxy) : void 0;
|
|
14392
14056
|
const chmodCaddyOnce = once(() => {
|
|
@@ -14402,7 +14066,7 @@ async function download() {
|
|
|
14402
14066
|
chmodCaddyOnce();
|
|
14403
14067
|
}).pipe(file).on("finish", () => {
|
|
14404
14068
|
logProgressOver();
|
|
14405
|
-
if (
|
|
14069
|
+
if (import_node_process8.default.platform === "win32")
|
|
14406
14070
|
return resolve2(caddyPath);
|
|
14407
14071
|
(0, import_node_fs4.chmodSync)(caddyPath, 493);
|
|
14408
14072
|
resolve2(caddyPath);
|
|
@@ -14452,26 +14116,17 @@ var defaultDependencies = {
|
|
|
14452
14116
|
caddyBin: caddyPath,
|
|
14453
14117
|
caddyConfigPath: caddyFilePath,
|
|
14454
14118
|
reason
|
|
14455
|
-
})
|
|
14119
|
+
}),
|
|
14120
|
+
config: () => getCaddyConfig()
|
|
14456
14121
|
};
|
|
14457
14122
|
var CaddyInstant = class {
|
|
14458
14123
|
constructor(deps = {}) {
|
|
14459
14124
|
this.inited = false;
|
|
14460
14125
|
this.stoped = false;
|
|
14461
|
-
/** has locked when start */
|
|
14462
|
-
this.locked = false;
|
|
14463
14126
|
this._stopEffects = [];
|
|
14127
|
+
/** Identifies this instance's routes in the shared config. */
|
|
14128
|
+
this.proxyKey = `${import_node_process8.default.pid}-${Math.random().toString(36).slice(2, 8)}`;
|
|
14464
14129
|
this.deps = { ...defaultDependencies, ...deps };
|
|
14465
|
-
this.locked = this.checkLock();
|
|
14466
|
-
}
|
|
14467
|
-
checkLock() {
|
|
14468
|
-
if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
|
|
14469
|
-
(0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
|
|
14470
|
-
try {
|
|
14471
|
-
return lockfile.checkSync(caddyLockFilePath);
|
|
14472
|
-
} catch {
|
|
14473
|
-
return false;
|
|
14474
|
-
}
|
|
14475
14130
|
}
|
|
14476
14131
|
/**
|
|
14477
14132
|
* Connects to the privileged helper, starting it once if needed. It is
|
|
@@ -14490,20 +14145,20 @@ var CaddyInstant = class {
|
|
|
14490
14145
|
this.caddyfile = "";
|
|
14491
14146
|
return "";
|
|
14492
14147
|
}
|
|
14493
|
-
this.caddyfile = await (0,
|
|
14148
|
+
this.caddyfile = await (0, import_promises2.readFile)(caddyFilePath, "utf-8");
|
|
14494
14149
|
return this.caddyfile;
|
|
14495
14150
|
}
|
|
14496
14151
|
get caddyRoot() {
|
|
14497
14152
|
return (0, import_node_path5.join)(
|
|
14498
|
-
|
|
14153
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14499
14154
|
"./pki/authorities/local"
|
|
14500
14155
|
);
|
|
14501
14156
|
}
|
|
14502
14157
|
async writeCaddyfile() {
|
|
14503
|
-
return await (0,
|
|
14158
|
+
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
|
14504
14159
|
}
|
|
14505
14160
|
async deleteCaddyfile() {
|
|
14506
|
-
return await (0,
|
|
14161
|
+
return await (0, import_promises2.unlink)(caddyFilePath);
|
|
14507
14162
|
}
|
|
14508
14163
|
async init() {
|
|
14509
14164
|
await download();
|
|
@@ -14541,9 +14196,15 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14541
14196
|
if (!health.healthy)
|
|
14542
14197
|
throw new Error(formatTlsHealthFailure(targetHost, health));
|
|
14543
14198
|
}
|
|
14199
|
+
/**
|
|
14200
|
+
* Regenerates the Caddyfile from the config on disk.
|
|
14201
|
+
*
|
|
14202
|
+
* Reading the file rather than a cached view matters here: another project
|
|
14203
|
+
* may have added its route since this instance last looked.
|
|
14204
|
+
*/
|
|
14544
14205
|
async updateCaddyfile() {
|
|
14545
|
-
const {
|
|
14546
|
-
const proxies = Object.values(
|
|
14206
|
+
const { readProxies } = this.deps.config();
|
|
14207
|
+
const proxies = Object.values(readProxies());
|
|
14547
14208
|
const ctx = validateTemplateContext({
|
|
14548
14209
|
caddy_root: this.caddyRoot,
|
|
14549
14210
|
proxies
|
|
@@ -14592,7 +14253,7 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14592
14253
|
const session = await this.session({ target: targetHost, https });
|
|
14593
14254
|
await session.client.call("hosts.add", { ip: sourceHost, host: targetHost });
|
|
14594
14255
|
consola.success("update host success\n");
|
|
14595
|
-
const
|
|
14256
|
+
const normalizeBase2 = (b) => {
|
|
14596
14257
|
let out = b || "/";
|
|
14597
14258
|
if (!out.startsWith("/"))
|
|
14598
14259
|
out = `/${out}`;
|
|
@@ -14600,7 +14261,7 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14600
14261
|
out = `${out}/`;
|
|
14601
14262
|
return out;
|
|
14602
14263
|
};
|
|
14603
|
-
const baseNormalized =
|
|
14264
|
+
const baseNormalized = normalizeBase2(base);
|
|
14604
14265
|
const proxies = [
|
|
14605
14266
|
{
|
|
14606
14267
|
target: targetHost,
|
|
@@ -14611,27 +14272,12 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14611
14272
|
healthCheck
|
|
14612
14273
|
}
|
|
14613
14274
|
];
|
|
14614
|
-
const { writeCaddyConfig } =
|
|
14615
|
-
writeCaddyConfig(proxies);
|
|
14275
|
+
const { writeCaddyConfig } = this.deps.config();
|
|
14276
|
+
await writeCaddyConfig(proxies, this.proxyKey);
|
|
14616
14277
|
await this.updateCaddyfile();
|
|
14617
|
-
|
|
14618
|
-
|
|
14619
|
-
|
|
14620
|
-
getCaddyConfig().configJsonRef();
|
|
14621
|
-
if (skipInitialCaddyfileEffect) {
|
|
14622
|
-
skipInitialCaddyfileEffect = false;
|
|
14623
|
-
return;
|
|
14624
|
-
}
|
|
14625
|
-
void this.updateCaddyfile();
|
|
14626
|
-
})
|
|
14627
|
-
);
|
|
14628
|
-
if (!(0, import_node_fs4.existsSync)(caddyLockFilePath))
|
|
14629
|
-
(0, import_node_fs4.writeFileSync)(caddyLockFilePath, "");
|
|
14630
|
-
if (!this.locked) {
|
|
14631
|
-
await session.client.call("port.free", { port: 443 });
|
|
14632
|
-
if (import_node_process7.default.platform === "win32" || !https)
|
|
14633
|
-
await session.client.call("port.free", { port: 80 });
|
|
14634
|
-
}
|
|
14278
|
+
await session.client.call("port.free", { port: 443 });
|
|
14279
|
+
if (import_node_process8.default.platform === "win32" || !https)
|
|
14280
|
+
await session.client.call("port.free", { port: 80 });
|
|
14635
14281
|
return new Promise((resolve2, reject2) => {
|
|
14636
14282
|
let startupCheckStarted = false;
|
|
14637
14283
|
const resolveWhenReady = async () => {
|
|
@@ -14645,106 +14291,89 @@ Run \`${caddyPath} trust\` manually if the browser warns about the certificate.`
|
|
|
14645
14291
|
}
|
|
14646
14292
|
resolve2();
|
|
14647
14293
|
} catch (error) {
|
|
14648
|
-
|
|
14649
|
-
await this.baseCleanup(restore);
|
|
14294
|
+
await this.baseCleanup(restore);
|
|
14650
14295
|
reject2(error);
|
|
14651
14296
|
}
|
|
14652
14297
|
};
|
|
14653
14298
|
const setupCleanup = () => {
|
|
14654
|
-
|
|
14299
|
+
import_node_process8.default.on("SIGINT", async () => {
|
|
14655
14300
|
if (this.stoped)
|
|
14656
14301
|
return;
|
|
14657
|
-
|
|
14302
|
+
import_node_process8.default.stdin.resume();
|
|
14658
14303
|
try {
|
|
14659
14304
|
await this.baseCleanup(restore);
|
|
14660
14305
|
} finally {
|
|
14661
14306
|
this.stoped = true;
|
|
14662
|
-
|
|
14663
|
-
|
|
14307
|
+
import_node_process8.default.nextTick(() => {
|
|
14308
|
+
import_node_process8.default.exit();
|
|
14664
14309
|
});
|
|
14665
14310
|
}
|
|
14666
14311
|
});
|
|
14667
|
-
const originalExit =
|
|
14668
|
-
|
|
14312
|
+
const originalExit = import_node_process8.default.exit.bind(import_node_process8.default);
|
|
14313
|
+
import_node_process8.default.exit = async (code) => {
|
|
14669
14314
|
if (this.stoped)
|
|
14670
14315
|
return originalExit(code);
|
|
14671
|
-
|
|
14316
|
+
import_node_process8.default.stdin.resume();
|
|
14672
14317
|
try {
|
|
14673
14318
|
await this.baseCleanup();
|
|
14674
14319
|
} finally {
|
|
14675
14320
|
this.stoped = true;
|
|
14676
|
-
|
|
14321
|
+
import_node_process8.default.nextTick(() => {
|
|
14677
14322
|
originalExit(code);
|
|
14678
14323
|
});
|
|
14679
14324
|
}
|
|
14680
14325
|
};
|
|
14681
14326
|
};
|
|
14682
|
-
|
|
14683
|
-
|
|
14684
|
-
|
|
14685
|
-
|
|
14686
|
-
|
|
14687
|
-
|
|
14688
|
-
|
|
14689
|
-
|
|
14690
|
-
|
|
14691
|
-
|
|
14692
|
-
|
|
14693
|
-
|
|
14694
|
-
|
|
14695
|
-
|
|
14696
|
-
|
|
14697
|
-
|
|
14698
|
-
|
|
14699
|
-
|
|
14700
|
-
|
|
14701
|
-
|
|
14702
|
-
|
|
14703
|
-
|
|
14704
|
-
if (line.includes("parsing caddyfile tokens")) {
|
|
14705
|
-
consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
|
|
14327
|
+
setupCleanup();
|
|
14328
|
+
void (async () => {
|
|
14329
|
+
try {
|
|
14330
|
+
const child = new HelperCaddyProcess(session.client);
|
|
14331
|
+
this._caddyChild = child;
|
|
14332
|
+
await session.client.call("caddy.start");
|
|
14333
|
+
child.on("exit", (code) => {
|
|
14334
|
+
if (code !== null && code !== 0)
|
|
14335
|
+
reject2(new Error(`Caddy exited with code ${code}`));
|
|
14336
|
+
});
|
|
14337
|
+
child.stderr.on("data", async (data) => {
|
|
14338
|
+
const lines = data.toString().split("\n").map((line) => line.trim());
|
|
14339
|
+
for (const line of lines) {
|
|
14340
|
+
showCaddyLog && line && console.info(line);
|
|
14341
|
+
if (isCaddyReloadCancellation(line)) {
|
|
14342
|
+
consola.info("Caddy restarted before TLS issuance completed; retrying.\n");
|
|
14343
|
+
continue;
|
|
14344
|
+
}
|
|
14345
|
+
try {
|
|
14346
|
+
if (line.includes("Error:") || line && JSON.parse(line).level === "error") {
|
|
14347
|
+
if (line.includes("parsing caddyfile tokens")) {
|
|
14348
|
+
consola.error("Caddyfile syntax error, please contact the author:\n", `${this.caddyfile}
|
|
14706
14349
|
|
|
14707
14350
|
${line}
|
|
14708
14351
|
`);
|
|
14709
|
-
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
14352
|
+
await this.baseCleanup();
|
|
14353
|
+
import_node_process8.default.exit();
|
|
14354
|
+
} else {
|
|
14355
|
+
consola.error(`${line}
|
|
14713
14356
|
`);
|
|
14714
|
-
|
|
14715
|
-
}
|
|
14357
|
+
return reject2(line);
|
|
14716
14358
|
}
|
|
14717
|
-
} catch {
|
|
14718
14359
|
}
|
|
14719
|
-
|
|
14720
|
-
consola.success("Detect added a new reverse proxy config, restarted.\n");
|
|
14721
|
-
if (line.includes("caddy proxying") || line.includes("serving initial"))
|
|
14722
|
-
void resolveWhenReady();
|
|
14360
|
+
} catch {
|
|
14723
14361
|
}
|
|
14724
|
-
|
|
14725
|
-
|
|
14726
|
-
|
|
14727
|
-
|
|
14728
|
-
}
|
|
14729
|
-
}
|
|
14730
|
-
|
|
14731
|
-
|
|
14732
|
-
|
|
14733
|
-
}
|
|
14734
|
-
}
|
|
14735
|
-
|
|
14736
|
-
|
|
14737
|
-
|
|
14738
|
-
|
|
14739
|
-
if (https)
|
|
14740
|
-
await this.ensureTlsReady(targetHost);
|
|
14741
|
-
setupCleanup();
|
|
14742
|
-
resolve2();
|
|
14743
|
-
} catch (error) {
|
|
14744
|
-
reject2(error);
|
|
14745
|
-
}
|
|
14746
|
-
})();
|
|
14747
|
-
}
|
|
14362
|
+
if (line.includes("config file changed"))
|
|
14363
|
+
consola.success("Detect added a new reverse proxy config, restarted.\n");
|
|
14364
|
+
if (line.includes("caddy proxying") || line.includes("serving initial"))
|
|
14365
|
+
void resolveWhenReady();
|
|
14366
|
+
}
|
|
14367
|
+
});
|
|
14368
|
+
child.stdout.on("data", (data) => {
|
|
14369
|
+
consola.info(data.toString());
|
|
14370
|
+
void resolveWhenReady();
|
|
14371
|
+
});
|
|
14372
|
+
} catch (error) {
|
|
14373
|
+
await this.baseCleanup(restore);
|
|
14374
|
+
reject2(error);
|
|
14375
|
+
}
|
|
14376
|
+
})();
|
|
14748
14377
|
});
|
|
14749
14378
|
}
|
|
14750
14379
|
async baseCleanup(restore = true) {
|
|
@@ -14768,18 +14397,9 @@ ${line}
|
|
|
14768
14397
|
consola.fail("Restore host failed.\n");
|
|
14769
14398
|
}
|
|
14770
14399
|
}
|
|
14771
|
-
if (!this.
|
|
14772
|
-
await this.stopCaddy();
|
|
14400
|
+
if (!this.stoped) {
|
|
14773
14401
|
try {
|
|
14774
|
-
await
|
|
14775
|
-
});
|
|
14776
|
-
await (0, import_promises3.unlink)(caddyFilePath).catch(() => {
|
|
14777
|
-
});
|
|
14778
|
-
await (0, import_promises3.unlink)(caddyLockFilePath).catch(() => {
|
|
14779
|
-
});
|
|
14780
|
-
if (caddyConfig) {
|
|
14781
|
-
await caddyConfig.cleanUp();
|
|
14782
|
-
}
|
|
14402
|
+
await this.deps.config().removeProxy(this.proxyKey);
|
|
14783
14403
|
} catch (e) {
|
|
14784
14404
|
consola.error(e);
|
|
14785
14405
|
}
|
|
@@ -15034,7 +14654,7 @@ function isPrivilegeDenied() {
|
|
|
15034
14654
|
var config;
|
|
15035
14655
|
var caddy;
|
|
15036
14656
|
var hmrSseBridgeActive = false;
|
|
15037
|
-
var cwd =
|
|
14657
|
+
var cwd = import_node_process9.default.cwd();
|
|
15038
14658
|
function colorUrl(url2) {
|
|
15039
14659
|
return import_picocolors2.default.green(url2.replace(/:(\d+)\//, (_, port) => `:${import_picocolors2.default.bold(port)}/`));
|
|
15040
14660
|
}
|
|
@@ -15145,7 +14765,7 @@ var unpluginFactory = (options) => ({
|
|
|
15145
14765
|
},
|
|
15146
14766
|
webpack(compiler) {
|
|
15147
14767
|
var _a4, _b3, _c2;
|
|
15148
|
-
if (
|
|
14768
|
+
if (import_node_process9.default.env.NODE_ENV !== "development")
|
|
15149
14769
|
return;
|
|
15150
14770
|
const {
|
|
15151
14771
|
enable = true,
|
|
@@ -15166,7 +14786,7 @@ var unpluginFactory = (options) => ({
|
|
|
15166
14786
|
port: 8080,
|
|
15167
14787
|
...compiler.options.devServer,
|
|
15168
14788
|
// @ts-expect-error vuecli
|
|
15169
|
-
...(_a4 =
|
|
14789
|
+
...(_a4 = import_node_process9.default.VUE_CLI_SERVICE) == null ? void 0 : _a4.projectOptions.devServer
|
|
15170
14790
|
};
|
|
15171
14791
|
const source = `${devServer.host}:${devServer.port}`;
|
|
15172
14792
|
if (isPrivilegeDenied())
|
|
@@ -15185,7 +14805,7 @@ var unpluginFactory = (options) => ({
|
|
|
15185
14805
|
const _close = (_c2 = compiler.close) == null ? void 0 : _c2.bind(compiler);
|
|
15186
14806
|
if (_close) {
|
|
15187
14807
|
compiler.close = async (callback) => {
|
|
15188
|
-
|
|
14808
|
+
import_node_process9.default.on("exit", () => {
|
|
15189
14809
|
_close && _close(callback);
|
|
15190
14810
|
});
|
|
15191
14811
|
};
|
|
@@ -15216,7 +14836,7 @@ var unpluginFactory = (options) => ({
|
|
|
15216
14836
|
},
|
|
15217
14837
|
async rspack(compiler) {
|
|
15218
14838
|
var _a4, _b3, _c2, _d2;
|
|
15219
|
-
if (
|
|
14839
|
+
if (import_node_process9.default.env.NODE_ENV !== "development")
|
|
15220
14840
|
return;
|
|
15221
14841
|
const {
|
|
15222
14842
|
enable = true,
|