unplugin-https-reverse-proxy 4.1.0-beta.8 → 4.1.0-beta.9
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-ICH7VY4H.js → chunk-3NHJSYFO.js} +30 -18
- package/dist/esbuild.cjs +30 -18
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +30 -18
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +30 -18
- package/dist/nuxt.js +1 -1
- package/dist/privileged-helper.cjs +19 -8
- package/dist/privileged-helper.js +19 -8
- package/dist/rollup.cjs +30 -18
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +30 -18
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +30 -18
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +30 -18
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
- package/src/caddy/config.ts +34 -19
- package/src/caddy/index.ts +26 -7
- package/src/privileged/server.ts +24 -0
- package/src/privileged-helper.ts +17 -9
|
@@ -13149,29 +13149,31 @@ function writeConfig(proxies) {
|
|
|
13149
13149
|
writeFileSync(temp, content);
|
|
13150
13150
|
renameSync(temp, caddyConfigPath);
|
|
13151
13151
|
}
|
|
13152
|
-
async function mutateConfig(lock3, mutate) {
|
|
13153
|
-
const release = await lock3.acquire();
|
|
13154
|
-
try {
|
|
13155
|
-
const proxies = readConfig();
|
|
13156
|
-
mutate(proxies);
|
|
13157
|
-
writeConfig(proxies);
|
|
13158
|
-
return proxies;
|
|
13159
|
-
} finally {
|
|
13160
|
-
release();
|
|
13161
|
-
}
|
|
13162
|
-
}
|
|
13163
13152
|
function useCaddyConfig(options = {}) {
|
|
13164
13153
|
const lock3 = options.lock ?? createFileLock();
|
|
13154
|
+
async function mutate(apply) {
|
|
13155
|
+
var _a4;
|
|
13156
|
+
const release = await lock3.acquire();
|
|
13157
|
+
try {
|
|
13158
|
+
const proxies = readConfig();
|
|
13159
|
+
apply(proxies);
|
|
13160
|
+
writeConfig(proxies);
|
|
13161
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13162
|
+
return proxies;
|
|
13163
|
+
} finally {
|
|
13164
|
+
release();
|
|
13165
|
+
}
|
|
13166
|
+
}
|
|
13165
13167
|
return {
|
|
13166
13168
|
configJsonRef: () => existsSync2(caddyConfigPath) ? readConfig() : void 0,
|
|
13167
13169
|
async writeCaddyConfig(_proxies, key) {
|
|
13168
|
-
await
|
|
13170
|
+
await mutate((proxies) => {
|
|
13169
13171
|
for (const p of _proxies)
|
|
13170
13172
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: process3.pid };
|
|
13171
13173
|
});
|
|
13172
13174
|
},
|
|
13173
13175
|
async removeProxy(key) {
|
|
13174
|
-
const proxies = await
|
|
13176
|
+
const proxies = await mutate((current) => {
|
|
13175
13177
|
for (const route of Object.keys(current)) {
|
|
13176
13178
|
if (route.endsWith(`#${key}`))
|
|
13177
13179
|
delete current[route];
|
|
@@ -14020,10 +14022,23 @@ function testCaddy() {
|
|
|
14020
14022
|
});
|
|
14021
14023
|
});
|
|
14022
14024
|
}
|
|
14025
|
+
function caddyRootPath() {
|
|
14026
|
+
return join6(
|
|
14027
|
+
process8.platform === "win32" ? `${process8.env.AppData}/Caddy` : `${process8.env.HOME}/Library/Application Support/Caddy`,
|
|
14028
|
+
"./pki/authorities/local"
|
|
14029
|
+
);
|
|
14030
|
+
}
|
|
14031
|
+
async function renderCaddyfile(proxies) {
|
|
14032
|
+
const ctx = validateTemplateContext({
|
|
14033
|
+
caddy_root: caddyRootPath(),
|
|
14034
|
+
proxies: Object.values(proxies)
|
|
14035
|
+
});
|
|
14036
|
+
await writeFile2(caddyFilePath, await genCaddyfile(ctx));
|
|
14037
|
+
}
|
|
14023
14038
|
var caddyConfig;
|
|
14024
14039
|
function getCaddyConfig() {
|
|
14025
14040
|
if (!caddyConfig) {
|
|
14026
|
-
caddyConfig = useCaddyConfig();
|
|
14041
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14027
14042
|
}
|
|
14028
14043
|
return caddyConfig;
|
|
14029
14044
|
}
|
|
@@ -14079,10 +14094,7 @@ var CaddyInstant = class {
|
|
|
14079
14094
|
return this.caddyfile;
|
|
14080
14095
|
}
|
|
14081
14096
|
get caddyRoot() {
|
|
14082
|
-
return
|
|
14083
|
-
process8.platform === "win32" ? `${process8.env.AppData}/Caddy` : `${process8.env.HOME}/Library/Application Support/Caddy`,
|
|
14084
|
-
"./pki/authorities/local"
|
|
14085
|
-
);
|
|
14097
|
+
return caddyRootPath();
|
|
14086
14098
|
}
|
|
14087
14099
|
async writeCaddyfile() {
|
|
14088
14100
|
return await writeFile2(caddyFilePath, this.caddyfile || "");
|
package/dist/esbuild.cjs
CHANGED
|
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
|
|
|
13197
13197
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13198
13198
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13199
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();
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
13200
|
function useCaddyConfig(options = {}) {
|
|
13212
13201
|
const lock3 = options.lock ?? createFileLock();
|
|
13202
|
+
async function mutate(apply) {
|
|
13203
|
+
var _a4;
|
|
13204
|
+
const release = await lock3.acquire();
|
|
13205
|
+
try {
|
|
13206
|
+
const proxies = readConfig();
|
|
13207
|
+
apply(proxies);
|
|
13208
|
+
writeConfig(proxies);
|
|
13209
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13210
|
+
return proxies;
|
|
13211
|
+
} finally {
|
|
13212
|
+
release();
|
|
13213
|
+
}
|
|
13214
|
+
}
|
|
13213
13215
|
return {
|
|
13214
13216
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13215
13217
|
async writeCaddyConfig(_proxies, key) {
|
|
13216
|
-
await
|
|
13218
|
+
await mutate((proxies) => {
|
|
13217
13219
|
for (const p of _proxies)
|
|
13218
13220
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13219
13221
|
});
|
|
13220
13222
|
},
|
|
13221
13223
|
async removeProxy(key) {
|
|
13222
|
-
const proxies = await
|
|
13224
|
+
const proxies = await mutate((current) => {
|
|
13223
13225
|
for (const route of Object.keys(current)) {
|
|
13224
13226
|
if (route.endsWith(`#${key}`))
|
|
13225
13227
|
delete current[route];
|
|
@@ -14120,10 +14122,23 @@ function testCaddy() {
|
|
|
14120
14122
|
});
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14125
|
+
function caddyRootPath() {
|
|
14126
|
+
return (0, import_node_path5.join)(
|
|
14127
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14128
|
+
"./pki/authorities/local"
|
|
14129
|
+
);
|
|
14130
|
+
}
|
|
14131
|
+
async function renderCaddyfile(proxies) {
|
|
14132
|
+
const ctx = validateTemplateContext({
|
|
14133
|
+
caddy_root: caddyRootPath(),
|
|
14134
|
+
proxies: Object.values(proxies)
|
|
14135
|
+
});
|
|
14136
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14137
|
+
}
|
|
14123
14138
|
var caddyConfig;
|
|
14124
14139
|
function getCaddyConfig() {
|
|
14125
14140
|
if (!caddyConfig) {
|
|
14126
|
-
caddyConfig = useCaddyConfig();
|
|
14141
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14127
14142
|
}
|
|
14128
14143
|
return caddyConfig;
|
|
14129
14144
|
}
|
|
@@ -14179,10 +14194,7 @@ var CaddyInstant = class {
|
|
|
14179
14194
|
return this.caddyfile;
|
|
14180
14195
|
}
|
|
14181
14196
|
get caddyRoot() {
|
|
14182
|
-
return (
|
|
14183
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14184
|
-
"./pki/authorities/local"
|
|
14185
|
-
);
|
|
14197
|
+
return caddyRootPath();
|
|
14186
14198
|
}
|
|
14187
14199
|
async writeCaddyfile() {
|
|
14188
14200
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
|
|
|
13197
13197
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13198
13198
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13199
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();
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
13200
|
function useCaddyConfig(options = {}) {
|
|
13212
13201
|
const lock3 = options.lock ?? createFileLock();
|
|
13202
|
+
async function mutate(apply) {
|
|
13203
|
+
var _a4;
|
|
13204
|
+
const release = await lock3.acquire();
|
|
13205
|
+
try {
|
|
13206
|
+
const proxies = readConfig();
|
|
13207
|
+
apply(proxies);
|
|
13208
|
+
writeConfig(proxies);
|
|
13209
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13210
|
+
return proxies;
|
|
13211
|
+
} finally {
|
|
13212
|
+
release();
|
|
13213
|
+
}
|
|
13214
|
+
}
|
|
13213
13215
|
return {
|
|
13214
13216
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13215
13217
|
async writeCaddyConfig(_proxies, key) {
|
|
13216
|
-
await
|
|
13218
|
+
await mutate((proxies) => {
|
|
13217
13219
|
for (const p of _proxies)
|
|
13218
13220
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13219
13221
|
});
|
|
13220
13222
|
},
|
|
13221
13223
|
async removeProxy(key) {
|
|
13222
|
-
const proxies = await
|
|
13224
|
+
const proxies = await mutate((current) => {
|
|
13223
13225
|
for (const route of Object.keys(current)) {
|
|
13224
13226
|
if (route.endsWith(`#${key}`))
|
|
13225
13227
|
delete current[route];
|
|
@@ -14120,10 +14122,23 @@ function testCaddy() {
|
|
|
14120
14122
|
});
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14125
|
+
function caddyRootPath() {
|
|
14126
|
+
return (0, import_node_path5.join)(
|
|
14127
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14128
|
+
"./pki/authorities/local"
|
|
14129
|
+
);
|
|
14130
|
+
}
|
|
14131
|
+
async function renderCaddyfile(proxies) {
|
|
14132
|
+
const ctx = validateTemplateContext({
|
|
14133
|
+
caddy_root: caddyRootPath(),
|
|
14134
|
+
proxies: Object.values(proxies)
|
|
14135
|
+
});
|
|
14136
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14137
|
+
}
|
|
14123
14138
|
var caddyConfig;
|
|
14124
14139
|
function getCaddyConfig() {
|
|
14125
14140
|
if (!caddyConfig) {
|
|
14126
|
-
caddyConfig = useCaddyConfig();
|
|
14141
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14127
14142
|
}
|
|
14128
14143
|
return caddyConfig;
|
|
14129
14144
|
}
|
|
@@ -14179,10 +14194,7 @@ var CaddyInstant = class {
|
|
|
14179
14194
|
return this.caddyfile;
|
|
14180
14195
|
}
|
|
14181
14196
|
get caddyRoot() {
|
|
14182
|
-
return (
|
|
14183
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14184
|
-
"./pki/authorities/local"
|
|
14185
|
-
);
|
|
14197
|
+
return caddyRootPath();
|
|
14186
14198
|
}
|
|
14187
14199
|
async writeCaddyfile() {
|
|
14188
14200
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -13198,29 +13198,31 @@ function writeConfig(proxies) {
|
|
|
13198
13198
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13199
13199
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13200
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
13201
|
function useCaddyConfig(options = {}) {
|
|
13213
13202
|
const lock3 = options.lock ?? createFileLock();
|
|
13203
|
+
async function mutate(apply) {
|
|
13204
|
+
var _a4;
|
|
13205
|
+
const release = await lock3.acquire();
|
|
13206
|
+
try {
|
|
13207
|
+
const proxies = readConfig();
|
|
13208
|
+
apply(proxies);
|
|
13209
|
+
writeConfig(proxies);
|
|
13210
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13211
|
+
return proxies;
|
|
13212
|
+
} finally {
|
|
13213
|
+
release();
|
|
13214
|
+
}
|
|
13215
|
+
}
|
|
13214
13216
|
return {
|
|
13215
13217
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13216
13218
|
async writeCaddyConfig(_proxies, key) {
|
|
13217
|
-
await
|
|
13219
|
+
await mutate((proxies) => {
|
|
13218
13220
|
for (const p of _proxies)
|
|
13219
13221
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13220
13222
|
});
|
|
13221
13223
|
},
|
|
13222
13224
|
async removeProxy(key) {
|
|
13223
|
-
const proxies = await
|
|
13225
|
+
const proxies = await mutate((current) => {
|
|
13224
13226
|
for (const route of Object.keys(current)) {
|
|
13225
13227
|
if (route.endsWith(`#${key}`))
|
|
13226
13228
|
delete current[route];
|
|
@@ -14121,10 +14123,23 @@ function testCaddy() {
|
|
|
14121
14123
|
});
|
|
14122
14124
|
});
|
|
14123
14125
|
}
|
|
14126
|
+
function caddyRootPath() {
|
|
14127
|
+
return (0, import_node_path5.join)(
|
|
14128
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14129
|
+
"./pki/authorities/local"
|
|
14130
|
+
);
|
|
14131
|
+
}
|
|
14132
|
+
async function renderCaddyfile(proxies) {
|
|
14133
|
+
const ctx = validateTemplateContext({
|
|
14134
|
+
caddy_root: caddyRootPath(),
|
|
14135
|
+
proxies: Object.values(proxies)
|
|
14136
|
+
});
|
|
14137
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14138
|
+
}
|
|
14124
14139
|
var caddyConfig;
|
|
14125
14140
|
function getCaddyConfig() {
|
|
14126
14141
|
if (!caddyConfig) {
|
|
14127
|
-
caddyConfig = useCaddyConfig();
|
|
14142
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14128
14143
|
}
|
|
14129
14144
|
return caddyConfig;
|
|
14130
14145
|
}
|
|
@@ -14180,10 +14195,7 @@ var CaddyInstant = class {
|
|
|
14180
14195
|
return this.caddyfile;
|
|
14181
14196
|
}
|
|
14182
14197
|
get caddyRoot() {
|
|
14183
|
-
return (
|
|
14184
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14185
|
-
"./pki/authorities/local"
|
|
14186
|
-
);
|
|
14198
|
+
return caddyRootPath();
|
|
14187
14199
|
}
|
|
14188
14200
|
async writeCaddyfile() {
|
|
14189
14201
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/nuxt.js
CHANGED
|
@@ -381,7 +381,8 @@ function createHelperRuntime(deps) {
|
|
|
381
381
|
await dispose();
|
|
382
382
|
},
|
|
383
383
|
dispose,
|
|
384
|
-
sweepStaleEntries
|
|
384
|
+
sweepStaleEntries,
|
|
385
|
+
clientCount: () => clients.size
|
|
385
386
|
};
|
|
386
387
|
}
|
|
387
388
|
async function reclaimTree(target, uid, gid) {
|
|
@@ -432,6 +433,14 @@ function createNodeHelperDeps(options) {
|
|
|
432
433
|
const log = options.log ?? ((message) => import_node_process.default.stdout.write(`${message}
|
|
433
434
|
`));
|
|
434
435
|
let caddy;
|
|
436
|
+
import_node_process.default.on("exit", () => {
|
|
437
|
+
if ((caddy == null ? void 0 : caddy.pid) === void 0)
|
|
438
|
+
return;
|
|
439
|
+
try {
|
|
440
|
+
import_node_process.default.kill(caddy.pid, "SIGTERM");
|
|
441
|
+
} catch {
|
|
442
|
+
}
|
|
443
|
+
});
|
|
435
444
|
return {
|
|
436
445
|
readHosts: () => (0, import_node_fs.readFileSync)(hostsPath, "utf8"),
|
|
437
446
|
writeHosts: (content) => {
|
|
@@ -476,7 +485,8 @@ function createNodeHelperDeps(options) {
|
|
|
476
485
|
const child = (0, import_node_child_process.spawn)(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
|
|
477
486
|
cwd: options.caddyCwd ?? import_node_process.default.cwd(),
|
|
478
487
|
env: { ...import_node_process.default.env, ...options.caddyEnv },
|
|
479
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
488
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
489
|
+
detached: (0, import_node_os.platform)() !== "win32"
|
|
480
490
|
});
|
|
481
491
|
const handle = {
|
|
482
492
|
pid: child.pid,
|
|
@@ -750,13 +760,14 @@ async function main() {
|
|
|
750
760
|
XDG_DATA_HOME: import_node_process3.default.env.XDG_DATA_HOME ?? ""
|
|
751
761
|
}
|
|
752
762
|
});
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
763
|
+
for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
|
|
764
|
+
import_node_process3.default.on(signal, () => {
|
|
765
|
+
});
|
|
766
|
+
import_node_process3.default.on("SIGTERM", () => {
|
|
767
|
+
if (helper.runtime.clientCount() > 0)
|
|
768
|
+
return;
|
|
756
769
|
void helper.runtime.dispose().finally(() => import_node_process3.default.exit(0));
|
|
757
|
-
};
|
|
758
|
-
import_node_process3.default.on("SIGTERM", shutdown);
|
|
759
|
-
import_node_process3.default.on("SIGHUP", shutdown);
|
|
770
|
+
});
|
|
760
771
|
import_node_process3.default.stdout.on("error", () => {
|
|
761
772
|
});
|
|
762
773
|
import_node_process3.default.stderr.on("error", () => {
|
|
@@ -355,7 +355,8 @@ function createHelperRuntime(deps) {
|
|
|
355
355
|
await dispose();
|
|
356
356
|
},
|
|
357
357
|
dispose,
|
|
358
|
-
sweepStaleEntries
|
|
358
|
+
sweepStaleEntries,
|
|
359
|
+
clientCount: () => clients.size
|
|
359
360
|
};
|
|
360
361
|
}
|
|
361
362
|
async function reclaimTree(target, uid, gid) {
|
|
@@ -406,6 +407,14 @@ function createNodeHelperDeps(options) {
|
|
|
406
407
|
const log = options.log ?? ((message) => process.stdout.write(`${message}
|
|
407
408
|
`));
|
|
408
409
|
let caddy;
|
|
410
|
+
process.on("exit", () => {
|
|
411
|
+
if ((caddy == null ? void 0 : caddy.pid) === void 0)
|
|
412
|
+
return;
|
|
413
|
+
try {
|
|
414
|
+
process.kill(caddy.pid, "SIGTERM");
|
|
415
|
+
} catch {
|
|
416
|
+
}
|
|
417
|
+
});
|
|
409
418
|
return {
|
|
410
419
|
readHosts: () => readFileSync(hostsPath, "utf8"),
|
|
411
420
|
writeHosts: (content) => {
|
|
@@ -450,7 +459,8 @@ function createNodeHelperDeps(options) {
|
|
|
450
459
|
const child = spawn(options.caddyBin, ["run", "--adapter", "caddyfile", "--config", options.caddyConfigPath, "--watch"], {
|
|
451
460
|
cwd: options.caddyCwd ?? process.cwd(),
|
|
452
461
|
env: { ...process.env, ...options.caddyEnv },
|
|
453
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
462
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
463
|
+
detached: platform() !== "win32"
|
|
454
464
|
});
|
|
455
465
|
const handle = {
|
|
456
466
|
pid: child.pid,
|
|
@@ -724,13 +734,14 @@ async function main() {
|
|
|
724
734
|
XDG_DATA_HOME: process3.env.XDG_DATA_HOME ?? ""
|
|
725
735
|
}
|
|
726
736
|
});
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
737
|
+
for (const signal of ["SIGINT", "SIGQUIT", "SIGTSTP", "SIGHUP"])
|
|
738
|
+
process3.on(signal, () => {
|
|
739
|
+
});
|
|
740
|
+
process3.on("SIGTERM", () => {
|
|
741
|
+
if (helper.runtime.clientCount() > 0)
|
|
742
|
+
return;
|
|
730
743
|
void helper.runtime.dispose().finally(() => process3.exit(0));
|
|
731
|
-
};
|
|
732
|
-
process3.on("SIGTERM", shutdown);
|
|
733
|
-
process3.on("SIGHUP", shutdown);
|
|
744
|
+
});
|
|
734
745
|
process3.stdout.on("error", () => {
|
|
735
746
|
});
|
|
736
747
|
process3.stderr.on("error", () => {
|
package/dist/rollup.cjs
CHANGED
|
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
|
|
|
13197
13197
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13198
13198
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13199
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();
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
13200
|
function useCaddyConfig(options = {}) {
|
|
13212
13201
|
const lock3 = options.lock ?? createFileLock();
|
|
13202
|
+
async function mutate(apply) {
|
|
13203
|
+
var _a4;
|
|
13204
|
+
const release = await lock3.acquire();
|
|
13205
|
+
try {
|
|
13206
|
+
const proxies = readConfig();
|
|
13207
|
+
apply(proxies);
|
|
13208
|
+
writeConfig(proxies);
|
|
13209
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13210
|
+
return proxies;
|
|
13211
|
+
} finally {
|
|
13212
|
+
release();
|
|
13213
|
+
}
|
|
13214
|
+
}
|
|
13213
13215
|
return {
|
|
13214
13216
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13215
13217
|
async writeCaddyConfig(_proxies, key) {
|
|
13216
|
-
await
|
|
13218
|
+
await mutate((proxies) => {
|
|
13217
13219
|
for (const p of _proxies)
|
|
13218
13220
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13219
13221
|
});
|
|
13220
13222
|
},
|
|
13221
13223
|
async removeProxy(key) {
|
|
13222
|
-
const proxies = await
|
|
13224
|
+
const proxies = await mutate((current) => {
|
|
13223
13225
|
for (const route of Object.keys(current)) {
|
|
13224
13226
|
if (route.endsWith(`#${key}`))
|
|
13225
13227
|
delete current[route];
|
|
@@ -14120,10 +14122,23 @@ function testCaddy() {
|
|
|
14120
14122
|
});
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14125
|
+
function caddyRootPath() {
|
|
14126
|
+
return (0, import_node_path5.join)(
|
|
14127
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14128
|
+
"./pki/authorities/local"
|
|
14129
|
+
);
|
|
14130
|
+
}
|
|
14131
|
+
async function renderCaddyfile(proxies) {
|
|
14132
|
+
const ctx = validateTemplateContext({
|
|
14133
|
+
caddy_root: caddyRootPath(),
|
|
14134
|
+
proxies: Object.values(proxies)
|
|
14135
|
+
});
|
|
14136
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14137
|
+
}
|
|
14123
14138
|
var caddyConfig;
|
|
14124
14139
|
function getCaddyConfig() {
|
|
14125
14140
|
if (!caddyConfig) {
|
|
14126
|
-
caddyConfig = useCaddyConfig();
|
|
14141
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14127
14142
|
}
|
|
14128
14143
|
return caddyConfig;
|
|
14129
14144
|
}
|
|
@@ -14179,10 +14194,7 @@ var CaddyInstant = class {
|
|
|
14179
14194
|
return this.caddyfile;
|
|
14180
14195
|
}
|
|
14181
14196
|
get caddyRoot() {
|
|
14182
|
-
return (
|
|
14183
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14184
|
-
"./pki/authorities/local"
|
|
14185
|
-
);
|
|
14197
|
+
return caddyRootPath();
|
|
14186
14198
|
}
|
|
14187
14199
|
async writeCaddyfile() {
|
|
14188
14200
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -13196,29 +13196,31 @@ function writeConfig(proxies) {
|
|
|
13196
13196
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13197
13197
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13198
13198
|
}
|
|
13199
|
-
async function mutateConfig(lock3, mutate) {
|
|
13200
|
-
const release = await lock3.acquire();
|
|
13201
|
-
try {
|
|
13202
|
-
const proxies = readConfig();
|
|
13203
|
-
mutate(proxies);
|
|
13204
|
-
writeConfig(proxies);
|
|
13205
|
-
return proxies;
|
|
13206
|
-
} finally {
|
|
13207
|
-
release();
|
|
13208
|
-
}
|
|
13209
|
-
}
|
|
13210
13199
|
function useCaddyConfig(options = {}) {
|
|
13211
13200
|
const lock3 = options.lock ?? createFileLock();
|
|
13201
|
+
async function mutate(apply) {
|
|
13202
|
+
var _a4;
|
|
13203
|
+
const release = await lock3.acquire();
|
|
13204
|
+
try {
|
|
13205
|
+
const proxies = readConfig();
|
|
13206
|
+
apply(proxies);
|
|
13207
|
+
writeConfig(proxies);
|
|
13208
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13209
|
+
return proxies;
|
|
13210
|
+
} finally {
|
|
13211
|
+
release();
|
|
13212
|
+
}
|
|
13213
|
+
}
|
|
13212
13214
|
return {
|
|
13213
13215
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13214
13216
|
async writeCaddyConfig(_proxies, key) {
|
|
13215
|
-
await
|
|
13217
|
+
await mutate((proxies) => {
|
|
13216
13218
|
for (const p of _proxies)
|
|
13217
13219
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13218
13220
|
});
|
|
13219
13221
|
},
|
|
13220
13222
|
async removeProxy(key) {
|
|
13221
|
-
const proxies = await
|
|
13223
|
+
const proxies = await mutate((current) => {
|
|
13222
13224
|
for (const route of Object.keys(current)) {
|
|
13223
13225
|
if (route.endsWith(`#${key}`))
|
|
13224
13226
|
delete current[route];
|
|
@@ -14119,10 +14121,23 @@ function testCaddy() {
|
|
|
14119
14121
|
});
|
|
14120
14122
|
});
|
|
14121
14123
|
}
|
|
14124
|
+
function caddyRootPath() {
|
|
14125
|
+
return (0, import_node_path5.join)(
|
|
14126
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14127
|
+
"./pki/authorities/local"
|
|
14128
|
+
);
|
|
14129
|
+
}
|
|
14130
|
+
async function renderCaddyfile(proxies) {
|
|
14131
|
+
const ctx = validateTemplateContext({
|
|
14132
|
+
caddy_root: caddyRootPath(),
|
|
14133
|
+
proxies: Object.values(proxies)
|
|
14134
|
+
});
|
|
14135
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14136
|
+
}
|
|
14122
14137
|
var caddyConfig;
|
|
14123
14138
|
function getCaddyConfig() {
|
|
14124
14139
|
if (!caddyConfig) {
|
|
14125
|
-
caddyConfig = useCaddyConfig();
|
|
14140
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14126
14141
|
}
|
|
14127
14142
|
return caddyConfig;
|
|
14128
14143
|
}
|
|
@@ -14178,10 +14193,7 @@ var CaddyInstant = class {
|
|
|
14178
14193
|
return this.caddyfile;
|
|
14179
14194
|
}
|
|
14180
14195
|
get caddyRoot() {
|
|
14181
|
-
return (
|
|
14182
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14183
|
-
"./pki/authorities/local"
|
|
14184
|
-
);
|
|
14196
|
+
return caddyRootPath();
|
|
14185
14197
|
}
|
|
14186
14198
|
async writeCaddyfile() {
|
|
14187
14199
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/rspack.js
CHANGED
package/dist/vite.cjs
CHANGED
|
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
|
|
|
13197
13197
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13198
13198
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13199
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();
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
13200
|
function useCaddyConfig(options = {}) {
|
|
13212
13201
|
const lock3 = options.lock ?? createFileLock();
|
|
13202
|
+
async function mutate(apply) {
|
|
13203
|
+
var _a4;
|
|
13204
|
+
const release = await lock3.acquire();
|
|
13205
|
+
try {
|
|
13206
|
+
const proxies = readConfig();
|
|
13207
|
+
apply(proxies);
|
|
13208
|
+
writeConfig(proxies);
|
|
13209
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13210
|
+
return proxies;
|
|
13211
|
+
} finally {
|
|
13212
|
+
release();
|
|
13213
|
+
}
|
|
13214
|
+
}
|
|
13213
13215
|
return {
|
|
13214
13216
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13215
13217
|
async writeCaddyConfig(_proxies, key) {
|
|
13216
|
-
await
|
|
13218
|
+
await mutate((proxies) => {
|
|
13217
13219
|
for (const p of _proxies)
|
|
13218
13220
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13219
13221
|
});
|
|
13220
13222
|
},
|
|
13221
13223
|
async removeProxy(key) {
|
|
13222
|
-
const proxies = await
|
|
13224
|
+
const proxies = await mutate((current) => {
|
|
13223
13225
|
for (const route of Object.keys(current)) {
|
|
13224
13226
|
if (route.endsWith(`#${key}`))
|
|
13225
13227
|
delete current[route];
|
|
@@ -14120,10 +14122,23 @@ function testCaddy() {
|
|
|
14120
14122
|
});
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14125
|
+
function caddyRootPath() {
|
|
14126
|
+
return (0, import_node_path5.join)(
|
|
14127
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14128
|
+
"./pki/authorities/local"
|
|
14129
|
+
);
|
|
14130
|
+
}
|
|
14131
|
+
async function renderCaddyfile(proxies) {
|
|
14132
|
+
const ctx = validateTemplateContext({
|
|
14133
|
+
caddy_root: caddyRootPath(),
|
|
14134
|
+
proxies: Object.values(proxies)
|
|
14135
|
+
});
|
|
14136
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14137
|
+
}
|
|
14123
14138
|
var caddyConfig;
|
|
14124
14139
|
function getCaddyConfig() {
|
|
14125
14140
|
if (!caddyConfig) {
|
|
14126
|
-
caddyConfig = useCaddyConfig();
|
|
14141
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14127
14142
|
}
|
|
14128
14143
|
return caddyConfig;
|
|
14129
14144
|
}
|
|
@@ -14179,10 +14194,7 @@ var CaddyInstant = class {
|
|
|
14179
14194
|
return this.caddyfile;
|
|
14180
14195
|
}
|
|
14181
14196
|
get caddyRoot() {
|
|
14182
|
-
return (
|
|
14183
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14184
|
-
"./pki/authorities/local"
|
|
14185
|
-
);
|
|
14197
|
+
return caddyRootPath();
|
|
14186
14198
|
}
|
|
14187
14199
|
async writeCaddyfile() {
|
|
14188
14200
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -13197,29 +13197,31 @@ function writeConfig(proxies) {
|
|
|
13197
13197
|
(0, import_node_fs.writeFileSync)(temp, content);
|
|
13198
13198
|
(0, import_node_fs.renameSync)(temp, caddyConfigPath);
|
|
13199
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();
|
|
13209
|
-
}
|
|
13210
|
-
}
|
|
13211
13200
|
function useCaddyConfig(options = {}) {
|
|
13212
13201
|
const lock3 = options.lock ?? createFileLock();
|
|
13202
|
+
async function mutate(apply) {
|
|
13203
|
+
var _a4;
|
|
13204
|
+
const release = await lock3.acquire();
|
|
13205
|
+
try {
|
|
13206
|
+
const proxies = readConfig();
|
|
13207
|
+
apply(proxies);
|
|
13208
|
+
writeConfig(proxies);
|
|
13209
|
+
await ((_a4 = options.renderCaddyfile) == null ? void 0 : _a4.call(options, proxies));
|
|
13210
|
+
return proxies;
|
|
13211
|
+
} finally {
|
|
13212
|
+
release();
|
|
13213
|
+
}
|
|
13214
|
+
}
|
|
13213
13215
|
return {
|
|
13214
13216
|
configJsonRef: () => (0, import_node_fs.existsSync)(caddyConfigPath) ? readConfig() : void 0,
|
|
13215
13217
|
async writeCaddyConfig(_proxies, key) {
|
|
13216
|
-
await
|
|
13218
|
+
await mutate((proxies) => {
|
|
13217
13219
|
for (const p of _proxies)
|
|
13218
13220
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: import_node_process2.default.pid };
|
|
13219
13221
|
});
|
|
13220
13222
|
},
|
|
13221
13223
|
async removeProxy(key) {
|
|
13222
|
-
const proxies = await
|
|
13224
|
+
const proxies = await mutate((current) => {
|
|
13223
13225
|
for (const route of Object.keys(current)) {
|
|
13224
13226
|
if (route.endsWith(`#${key}`))
|
|
13225
13227
|
delete current[route];
|
|
@@ -14120,10 +14122,23 @@ function testCaddy() {
|
|
|
14120
14122
|
});
|
|
14121
14123
|
});
|
|
14122
14124
|
}
|
|
14125
|
+
function caddyRootPath() {
|
|
14126
|
+
return (0, import_node_path5.join)(
|
|
14127
|
+
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14128
|
+
"./pki/authorities/local"
|
|
14129
|
+
);
|
|
14130
|
+
}
|
|
14131
|
+
async function renderCaddyfile(proxies) {
|
|
14132
|
+
const ctx = validateTemplateContext({
|
|
14133
|
+
caddy_root: caddyRootPath(),
|
|
14134
|
+
proxies: Object.values(proxies)
|
|
14135
|
+
});
|
|
14136
|
+
await (0, import_promises2.writeFile)(caddyFilePath, await genCaddyfile(ctx));
|
|
14137
|
+
}
|
|
14123
14138
|
var caddyConfig;
|
|
14124
14139
|
function getCaddyConfig() {
|
|
14125
14140
|
if (!caddyConfig) {
|
|
14126
|
-
caddyConfig = useCaddyConfig();
|
|
14141
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile });
|
|
14127
14142
|
}
|
|
14128
14143
|
return caddyConfig;
|
|
14129
14144
|
}
|
|
@@ -14179,10 +14194,7 @@ var CaddyInstant = class {
|
|
|
14179
14194
|
return this.caddyfile;
|
|
14180
14195
|
}
|
|
14181
14196
|
get caddyRoot() {
|
|
14182
|
-
return (
|
|
14183
|
-
import_node_process8.default.platform === "win32" ? `${import_node_process8.default.env.AppData}/Caddy` : `${import_node_process8.default.env.HOME}/Library/Application Support/Caddy`,
|
|
14184
|
-
"./pki/authorities/local"
|
|
14185
|
-
);
|
|
14197
|
+
return caddyRootPath();
|
|
14186
14198
|
}
|
|
14187
14199
|
async writeCaddyfile() {
|
|
14188
14200
|
return await (0, import_promises2.writeFile)(caddyFilePath, this.caddyfile || "");
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
package/src/caddy/config.ts
CHANGED
|
@@ -84,43 +84,58 @@ function writeConfig(proxies: ProxyMap): void {
|
|
|
84
84
|
renameSync(temp, caddyConfigPath)
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
/** Applies `mutate` under the file lock, re-reading the latest state first. */
|
|
88
|
-
async function mutateConfig(
|
|
89
|
-
lock: ConfigLock,
|
|
90
|
-
mutate: (proxies: ProxyMap) => void,
|
|
91
|
-
): Promise<ProxyMap> {
|
|
92
|
-
const release = await lock.acquire()
|
|
93
|
-
try {
|
|
94
|
-
const proxies = readConfig()
|
|
95
|
-
mutate(proxies)
|
|
96
|
-
writeConfig(proxies)
|
|
97
|
-
return proxies
|
|
98
|
-
}
|
|
99
|
-
finally {
|
|
100
|
-
release()
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
87
|
export interface CaddyConfigOptions {
|
|
105
88
|
/** Injected in tests so they do not need the real lock. */
|
|
106
89
|
lock?: ConfigLock
|
|
90
|
+
/**
|
|
91
|
+
* Renders the Caddyfile from the routes, called inside the config lock.
|
|
92
|
+
*
|
|
93
|
+
* Rendering here rather than in the caller is what keeps the file in step
|
|
94
|
+
* with the JSON: two projects writing concurrently would otherwise render
|
|
95
|
+
* from their own stale view and the later write would win.
|
|
96
|
+
*/
|
|
97
|
+
renderCaddyfile?: (proxies: ProxyMap) => Promise<void>
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
export function useCaddyConfig(options: CaddyConfigOptions = {}): CaddyConfigApi {
|
|
110
101
|
const lock = options.lock ?? createFileLock()
|
|
111
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Applies the change, then re-renders while still holding the lock.
|
|
105
|
+
*
|
|
106
|
+
* The Caddyfile has to follow every change: leaving a stopped project's site
|
|
107
|
+
* in it would keep proxying to an upstream that is gone. Doing it inside the
|
|
108
|
+
* lock also picks up routes whose owner process died, since `readConfig`
|
|
109
|
+
* drops those.
|
|
110
|
+
*/
|
|
111
|
+
async function mutate(
|
|
112
|
+
apply: (proxies: ProxyMap) => void,
|
|
113
|
+
): Promise<ProxyMap> {
|
|
114
|
+
const release = await lock.acquire()
|
|
115
|
+
try {
|
|
116
|
+
const proxies = readConfig()
|
|
117
|
+
apply(proxies)
|
|
118
|
+
writeConfig(proxies)
|
|
119
|
+
await options.renderCaddyfile?.(proxies)
|
|
120
|
+
return proxies
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
release()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
112
127
|
return {
|
|
113
128
|
configJsonRef: () => (existsSync(caddyConfigPath) ? readConfig() : undefined),
|
|
114
129
|
|
|
115
130
|
async writeCaddyConfig(_proxies, key) {
|
|
116
|
-
await
|
|
131
|
+
await mutate((proxies) => {
|
|
117
132
|
for (const p of _proxies)
|
|
118
133
|
proxies[routeKey(p, key)] = { ...p, base: normalizeBase(p.base), ownerPid: process.pid }
|
|
119
134
|
})
|
|
120
135
|
},
|
|
121
136
|
|
|
122
137
|
async removeProxy(key) {
|
|
123
|
-
const proxies = await
|
|
138
|
+
const proxies = await mutate((current) => {
|
|
124
139
|
for (const route of Object.keys(current)) {
|
|
125
140
|
if (route.endsWith(`#${key}`))
|
|
126
141
|
delete current[route]
|
package/src/caddy/index.ts
CHANGED
|
@@ -106,11 +106,35 @@ interface RunOptions {
|
|
|
106
106
|
healthCheck?: boolean
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Where Caddy keeps the local CA; the template serves it for device installs. */
|
|
110
|
+
function caddyRootPath(): string {
|
|
111
|
+
return join(
|
|
112
|
+
process.platform === 'win32'
|
|
113
|
+
? `${process.env.AppData!}/Caddy`
|
|
114
|
+
: `${process.env.HOME!}/Library/Application Support/Caddy`,
|
|
115
|
+
'./pki/authorities/local',
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Renders the Caddyfile from the routes currently on disk and writes it.
|
|
121
|
+
*
|
|
122
|
+
* Called from inside the config lock, so two projects writing at once cannot
|
|
123
|
+
* render from their own stale view of the routes.
|
|
124
|
+
*/
|
|
125
|
+
async function renderCaddyfile(proxies: Record<string, unknown>): Promise<void> {
|
|
126
|
+
const ctx = validateTemplateContext({
|
|
127
|
+
caddy_root: caddyRootPath(),
|
|
128
|
+
proxies: Object.values(proxies) as never,
|
|
129
|
+
})
|
|
130
|
+
await writeFile(caddyFilePath, await genCaddyfile(ctx))
|
|
131
|
+
}
|
|
132
|
+
|
|
109
133
|
let caddyConfig: ReturnType<typeof useCaddyConfig> | undefined
|
|
110
134
|
|
|
111
135
|
function getCaddyConfig(): ReturnType<typeof useCaddyConfig> {
|
|
112
136
|
if (!caddyConfig) {
|
|
113
|
-
caddyConfig = useCaddyConfig()
|
|
137
|
+
caddyConfig = useCaddyConfig({ renderCaddyfile: renderCaddyfile as never })
|
|
114
138
|
}
|
|
115
139
|
return caddyConfig
|
|
116
140
|
}
|
|
@@ -194,12 +218,7 @@ export class CaddyInstant {
|
|
|
194
218
|
}
|
|
195
219
|
|
|
196
220
|
get caddyRoot(): string {
|
|
197
|
-
return
|
|
198
|
-
process.platform === 'win32'
|
|
199
|
-
? `${process.env.AppData!}/Caddy`
|
|
200
|
-
: `${process.env.HOME!}/Library/Application Support/Caddy`,
|
|
201
|
-
'./pki/authorities/local',
|
|
202
|
-
)
|
|
221
|
+
return caddyRootPath()
|
|
203
222
|
}
|
|
204
223
|
|
|
205
224
|
async writeCaddyfile(): Promise<void> {
|
package/src/privileged/server.ts
CHANGED
|
@@ -104,6 +104,8 @@ export interface HelperRuntime {
|
|
|
104
104
|
dispose: () => Promise<void>
|
|
105
105
|
/** Removes hosts entries a previous crashed session left behind. */
|
|
106
106
|
sweepStaleEntries: () => Promise<boolean>
|
|
107
|
+
/** Number of attached dev servers; a signal must not tear down a live one. */
|
|
108
|
+
clientCount: () => number
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
/**
|
|
@@ -332,6 +334,7 @@ export function createHelperRuntime(deps: HelperDeps): HelperRuntime {
|
|
|
332
334
|
},
|
|
333
335
|
dispose,
|
|
334
336
|
sweepStaleEntries,
|
|
337
|
+
clientCount: () => clients.size,
|
|
335
338
|
}
|
|
336
339
|
}
|
|
337
340
|
|
|
@@ -413,6 +416,19 @@ export function createNodeHelperDeps(options: NodeHelperDepsOptions): HelperDeps
|
|
|
413
416
|
const log = options.log ?? ((message: string) => process.stdout.write(`${message}\n`))
|
|
414
417
|
let caddy: CaddyChild | undefined
|
|
415
418
|
|
|
419
|
+
// Caddy runs in its own session, so it no longer dies with this process. The
|
|
420
|
+
// `exit` hook is the last chance to take it down; it must stay synchronous,
|
|
421
|
+
// which `kill` is. Nothing runs after SIGKILL, and that case is covered by
|
|
422
|
+
// the next start freeing the port.
|
|
423
|
+
process.on('exit', () => {
|
|
424
|
+
if (caddy?.pid === undefined)
|
|
425
|
+
return
|
|
426
|
+
try {
|
|
427
|
+
process.kill(caddy.pid, 'SIGTERM')
|
|
428
|
+
}
|
|
429
|
+
catch {}
|
|
430
|
+
})
|
|
431
|
+
|
|
416
432
|
return {
|
|
417
433
|
readHosts: () => readFileSync(hostsPath, 'utf8'),
|
|
418
434
|
writeHosts: (content) => {
|
|
@@ -465,10 +481,18 @@ export function createNodeHelperDeps(options: NodeHelperDepsOptions): HelperDeps
|
|
|
465
481
|
startCaddy: (emit) => {
|
|
466
482
|
// `--watch` makes Caddy reload when another project rewrites the shared
|
|
467
483
|
// Caddyfile. Without it the second project's route never takes effect.
|
|
484
|
+
//
|
|
485
|
+
// `detached` puts Caddy in its own session. It shares one Caddy between
|
|
486
|
+
// projects, so the Ctrl+C that stops one dev server must not reach it:
|
|
487
|
+
// the whole foreground process group gets SIGINT, and Caddy exits on
|
|
488
|
+
// SIGINT. `kill()` still targets the pid, and the exit event still fires.
|
|
489
|
+
// Windows has no process groups to escape and `detached` would open a
|
|
490
|
+
// console window there, so it stays off.
|
|
468
491
|
const child = spawn(options.caddyBin, ['run', '--adapter', 'caddyfile', '--config', options.caddyConfigPath, '--watch'], {
|
|
469
492
|
cwd: options.caddyCwd ?? process.cwd(),
|
|
470
493
|
env: { ...process.env, ...options.caddyEnv },
|
|
471
494
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
495
|
+
detached: platform() !== 'win32',
|
|
472
496
|
})
|
|
473
497
|
const handle: CaddyChild & { running?: boolean } = {
|
|
474
498
|
pid: child.pid,
|
package/src/privileged-helper.ts
CHANGED
|
@@ -86,17 +86,25 @@ async function main(): Promise<void> {
|
|
|
86
86
|
},
|
|
87
87
|
})
|
|
88
88
|
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
89
|
+
// Terminal signals reach the whole foreground process group, so they also hit
|
|
90
|
+
// this helper when one of several dev servers stops. Acting on them would tear
|
|
91
|
+
// down the shared Caddy and hosts entries the remaining projects still use.
|
|
92
|
+
// The socket closing is the only signal this helper acts on.
|
|
93
|
+
//
|
|
94
|
+
// Ctrl+C, Ctrl+\, Ctrl+Z and a terminal closing all arrive this way: SIGINT,
|
|
95
|
+
// SIGQUIT, SIGTSTP and SIGHUP. Ignoring SIGTSTP also keeps the helper from
|
|
96
|
+
// being suspended, which would stall every attached project's RPC.
|
|
97
|
+
for (const signal of ['SIGINT', 'SIGQUIT', 'SIGTSTP', 'SIGHUP'] as const)
|
|
98
|
+
process.on(signal, () => {})
|
|
93
99
|
|
|
94
|
-
|
|
100
|
+
// SIGTERM is different: IDE and process-tree runners send it to shut the tool
|
|
101
|
+
// down for real. It still must not drop a live session, so it only tears down
|
|
102
|
+
// when no dev server is attached.
|
|
103
|
+
process.on('SIGTERM', () => {
|
|
104
|
+
if (helper.runtime.clientCount() > 0)
|
|
105
|
+
return
|
|
95
106
|
void helper.runtime.dispose().finally(() => process.exit(0))
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
process.on('SIGTERM', shutdown)
|
|
99
|
-
process.on('SIGHUP', shutdown)
|
|
107
|
+
})
|
|
100
108
|
|
|
101
109
|
// A closed stdout (the parent died) must not interrupt the cleanup path.
|
|
102
110
|
process.stdout.on('error', () => {})
|