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