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