@foxford/den 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.mdx +13 -0
- package/adapter.cjs +2 -3
- package/adapter.js +1 -2
- package/bin/den.cjs +31 -51
- package/bin/den.js +31 -51
- package/builder/index.cjs +2 -3
- package/builder/index.d.cts +3 -2
- package/builder/index.d.ts +3 -2
- package/builder/index.js +1 -2
- package/{chunk-E56BKBQZ.js → chunk-AS6ZNCUY.js} +7 -7
- package/{chunk-H5DKRHHQ.cjs → chunk-BFRLBMH2.cjs} +8 -8
- package/chunk-ETO2T2TA.cjs +503 -0
- package/{chunk-E23E2VUC.js → chunk-HWDDAFGV.js} +1 -1
- package/{chunk-XQ7EHXHG.js → chunk-JW24N6O4.js} +47 -55
- package/{chunk-HJFBEJT6.cjs → chunk-MH2WIOTQ.cjs} +50 -58
- package/{chunk-XOJ2VWX4.cjs → chunk-MWDNN7Q4.cjs} +1 -1
- package/{chunk-QTWJTYZW.cjs → chunk-NOI7FSBX.cjs} +47 -55
- package/{chunk-A2CYL5LY.js → chunk-VCIMVMHG.js} +49 -57
- package/{chunk-WBHHHICS.js → chunk-WKCIOQOY.js} +1 -1
- package/{chunk-C7BM4DGX.cjs → chunk-Y7DGFJFA.cjs} +1 -1
- package/chunk-YWWRJMWN.js +503 -0
- package/define.cjs +3 -4
- package/define.js +2 -3
- package/index.cjs +54 -71
- package/index.js +53 -70
- package/island/index.cjs +5 -8
- package/island/index.js +4 -7
- package/ops/index.cjs +2 -3
- package/ops/index.js +1 -2
- package/package.json +17 -18
- package/serve/index.cjs +260 -273
- package/serve/index.js +257 -270
- package/chunk-6FNC3XMI.js +0 -45
- package/chunk-7FOG2MJV.js +0 -559
- package/chunk-IATA5QZ7.cjs +0 -559
- package/chunk-T5QVCXVB.cjs +0 -45
package/serve/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
normalizeRoutes,
|
|
7
7
|
parseCookieHeader,
|
|
8
8
|
renderApp
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-JW24N6O4.js";
|
|
10
|
+
import "../chunk-HWDDAFGV.js";
|
|
11
11
|
import "../chunk-3RX2OSUL.js";
|
|
12
12
|
import {
|
|
13
13
|
logger
|
|
@@ -18,12 +18,7 @@ import {
|
|
|
18
18
|
getProcessMetrics,
|
|
19
19
|
isOpsPath,
|
|
20
20
|
startOpsServer
|
|
21
|
-
} from "../chunk-
|
|
22
|
-
import {
|
|
23
|
-
__async,
|
|
24
|
-
__spreadProps,
|
|
25
|
-
__spreadValues
|
|
26
|
-
} from "../chunk-6FNC3XMI.js";
|
|
21
|
+
} from "../chunk-VCIMVMHG.js";
|
|
27
22
|
|
|
28
23
|
// src/serve/index.ts
|
|
29
24
|
import Fastify from "fastify";
|
|
@@ -51,7 +46,7 @@ var MIME = {
|
|
|
51
46
|
var HASHED_DIR = "assets/";
|
|
52
47
|
function assetsPrefix(base) {
|
|
53
48
|
const { pathname } = new URL(base, "http://assets.invalid");
|
|
54
|
-
return pathname.endsWith("/") ? pathname :
|
|
49
|
+
return pathname.endsWith("/") ? pathname : "".concat(pathname, "/");
|
|
55
50
|
}
|
|
56
51
|
function assetFile(dir, relative) {
|
|
57
52
|
const file = path.normalize(path.join(dir, relative));
|
|
@@ -60,7 +55,7 @@ function assetFile(dir, relative) {
|
|
|
60
55
|
function registerAssets(instance, source) {
|
|
61
56
|
const dir = path.resolve(source.dir);
|
|
62
57
|
const prefix = assetsPrefix(source.base);
|
|
63
|
-
instance.get(
|
|
58
|
+
instance.get("".concat(prefix, "*"), (request, reply) => {
|
|
64
59
|
var _a;
|
|
65
60
|
const relative = request.params["*"];
|
|
66
61
|
const file = assetFile(dir, relative);
|
|
@@ -100,7 +95,10 @@ function requestContextOf(req, fromBody) {
|
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
const cookie = req.headers.cookie;
|
|
103
|
-
const backendHeaders =
|
|
98
|
+
const backendHeaders = {
|
|
99
|
+
...typeof cookie === "string" && cookie !== "" ? { cookie } : {},
|
|
100
|
+
...fromBody
|
|
101
|
+
};
|
|
104
102
|
return { backendHeaders, cookies: parseCookieHeader(cookie), headers };
|
|
105
103
|
}
|
|
106
104
|
function backendHeadersOf(value) {
|
|
@@ -125,43 +123,41 @@ var appPlugin = (instance, options) => {
|
|
|
125
123
|
void reply.header("cache-control", "no-store");
|
|
126
124
|
return claim(app);
|
|
127
125
|
});
|
|
128
|
-
function handleRender(req, reply, target, inputs, rawBackendHeaders) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
serveLog.warn(`\u043C\u0435\u0434\u043B\u0435\u043D\u043D\u044B\u0439 \u0440\u0435\u043D\u0434\u0435\u0440 \xAB${pathname}\xBB: ${String(elapsed)}\u043C\u0441`);
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
serveLog.error(`\u0440\u0435\u043D\u0434\u0435\u0440 \xAB${pathname}\xBB \u0443\u043F\u0430\u043B \u0437\u0430 ${String(Date.now() - startedAt)}\u043C\u0441`, error);
|
|
162
|
-
return reply.send(error instanceof Error ? error : new Error(String(error)));
|
|
126
|
+
async function handleRender(req, reply, target, inputs, rawBackendHeaders) {
|
|
127
|
+
if (typeof target !== "string" || !target.startsWith("/")) {
|
|
128
|
+
return reply.code(400).send({ error: "\u043D\u0435 \u043F\u0435\u0440\u0435\u0434\u0430\u043D \u0438\u043B\u0438 \u043D\u0435\u0432\u0430\u043B\u0438\u0434\u0435\u043D \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440 url" });
|
|
129
|
+
}
|
|
130
|
+
if (inputs !== void 0 && (typeof inputs !== "object" || inputs === null || Array.isArray(inputs))) {
|
|
131
|
+
return reply.code(400).send({ error: "inputs \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u043E\u0431\u044A\u0435\u043A\u0442\u043E\u043C \u043F\u043E \u043A\u043B\u044E\u0447\u0443 token.description" });
|
|
132
|
+
}
|
|
133
|
+
const backendHeaders = backendHeadersOf(rawBackendHeaders);
|
|
134
|
+
if (backendHeaders === "invalid") {
|
|
135
|
+
return reply.code(400).send({ error: "backendHeaders \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u043E\u0431\u044A\u0435\u043A\u0442\u043E\u043C \xAB\u0438\u043C\u044F \u0437\u0430\u0433\u043E\u043B\u043E\u0432\u043A\u0430 \u2192 \u0441\u0442\u0440\u043E\u043A\u0430\xBB" });
|
|
136
|
+
}
|
|
137
|
+
const { pathname, search } = new URL(target, "http://localhost");
|
|
138
|
+
const params = matchClaim(app, pathname);
|
|
139
|
+
if (params === null) {
|
|
140
|
+
serveLog.error("\u043F\u0443\u0442\u044C \xAB".concat(pathname, "\xBB \u0432\u043D\u0435 \u0437\u0430\u044F\u0432\u043A\u0438 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F"));
|
|
141
|
+
return reply.code(404).send({ error: "\u043F\u0443\u0442\u044C \xAB".concat(pathname, "\xBB \u0432\u043D\u0435 \u0437\u0430\u044F\u0432\u043A\u0438 \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u044F") });
|
|
142
|
+
}
|
|
143
|
+
const startedAt = Date.now();
|
|
144
|
+
try {
|
|
145
|
+
const result = await renderApp(app, {
|
|
146
|
+
context: requestContextOf(req, backendHeaders),
|
|
147
|
+
inputs,
|
|
148
|
+
params,
|
|
149
|
+
pathname,
|
|
150
|
+
search
|
|
151
|
+
});
|
|
152
|
+
const elapsed = Date.now() - startedAt;
|
|
153
|
+
if (elapsed >= slowRenderMs) {
|
|
154
|
+
serveLog.warn("\u043C\u0435\u0434\u043B\u0435\u043D\u043D\u044B\u0439 \u0440\u0435\u043D\u0434\u0435\u0440 \xAB".concat(pathname, "\xBB: ").concat(String(elapsed), "\u043C\u0441"));
|
|
163
155
|
}
|
|
164
|
-
|
|
156
|
+
return result;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
serveLog.error("\u0440\u0435\u043D\u0434\u0435\u0440 \xAB".concat(pathname, "\xBB \u0443\u043F\u0430\u043B \u0437\u0430 ").concat(String(Date.now() - startedAt), "\u043C\u0441"), error);
|
|
159
|
+
return reply.send(error instanceof Error ? error : new Error(String(error)));
|
|
160
|
+
}
|
|
165
161
|
}
|
|
166
162
|
instance.get(
|
|
167
163
|
"/_render",
|
|
@@ -188,187 +184,180 @@ import { log as log2 } from "@foxford/logger";
|
|
|
188
184
|
var ALIVE = "den:app-worker-alive";
|
|
189
185
|
var SIGNALS = ["SIGTERM", "SIGINT"];
|
|
190
186
|
var SHUTDOWN_MS = 1e4;
|
|
191
|
-
function startWorker(appName, start) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
187
|
+
async function startWorker(appName, start) {
|
|
188
|
+
const aggregation = clusterMetrics();
|
|
189
|
+
const logger2 = log2.getLogger(appName).getLogger("cluster");
|
|
190
|
+
let timer;
|
|
191
|
+
let closing;
|
|
192
|
+
const starting = start();
|
|
193
|
+
const close = () => {
|
|
194
|
+
closing != null ? closing : closing = (async () => {
|
|
195
|
+
clearInterval(timer);
|
|
196
|
+
try {
|
|
197
|
+
const instance = await starting;
|
|
198
|
+
await instance.close();
|
|
199
|
+
} finally {
|
|
201
200
|
try {
|
|
202
|
-
|
|
203
|
-
yield instance.close();
|
|
201
|
+
if (process.connected) await aggregation.shutdown();
|
|
204
202
|
} finally {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
for (const signal of SIGNALS) process.removeListener(signal, shutdown);
|
|
209
|
-
process.removeListener("disconnect", shutdown);
|
|
210
|
-
if (process.connected) process.disconnect();
|
|
211
|
-
}
|
|
203
|
+
for (const signal of SIGNALS) process.removeListener(signal, shutdown);
|
|
204
|
+
process.removeListener("disconnect", shutdown);
|
|
205
|
+
if (process.connected) process.disconnect();
|
|
212
206
|
}
|
|
213
|
-
}))();
|
|
214
|
-
return closing;
|
|
215
|
-
};
|
|
216
|
-
const shutdown = () => {
|
|
217
|
-
const deadline = setTimeout(() => process.exit(1), SHUTDOWN_MS);
|
|
218
|
-
deadline.unref();
|
|
219
|
-
void close().then(() => process.exit(0)).catch((error) => {
|
|
220
|
-
logger2.error("\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430 \u0432\u043E\u0440\u043A\u0435\u0440\u0430 \u043D\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0430\u0441\u044C:", error);
|
|
221
|
-
process.exit(1);
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
for (const signal of SIGNALS) process.on(signal, shutdown);
|
|
225
|
-
process.once("disconnect", shutdown);
|
|
226
|
-
try {
|
|
227
|
-
yield starting;
|
|
228
|
-
if (!closing) {
|
|
229
|
-
const notify = () => {
|
|
230
|
-
var _a;
|
|
231
|
-
if (process.connected) (_a = process.send) == null ? void 0 : _a.call(process, { type: ALIVE });
|
|
232
|
-
};
|
|
233
|
-
timer = setInterval(notify, 2e3);
|
|
234
|
-
timer.unref();
|
|
235
|
-
notify();
|
|
236
207
|
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
208
|
+
})();
|
|
209
|
+
return closing;
|
|
210
|
+
};
|
|
211
|
+
const shutdown = () => {
|
|
212
|
+
const deadline = setTimeout(() => process.exit(1), SHUTDOWN_MS);
|
|
213
|
+
deadline.unref();
|
|
214
|
+
void close().then(() => process.exit(0)).catch((error) => {
|
|
215
|
+
logger2.error("\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430 \u0432\u043E\u0440\u043A\u0435\u0440\u0430 \u043D\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0430\u0441\u044C:", error);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
for (const signal of SIGNALS) process.on(signal, shutdown);
|
|
220
|
+
process.once("disconnect", shutdown);
|
|
221
|
+
try {
|
|
222
|
+
await starting;
|
|
223
|
+
if (!closing) {
|
|
224
|
+
const notify = () => {
|
|
225
|
+
var _a;
|
|
226
|
+
if (process.connected) (_a = process.send) == null ? void 0 : _a.call(process, { type: ALIVE });
|
|
227
|
+
};
|
|
228
|
+
timer = setInterval(notify, 2e3);
|
|
229
|
+
timer.unref();
|
|
230
|
+
notify();
|
|
240
231
|
}
|
|
241
|
-
|
|
242
|
-
|
|
232
|
+
} catch (error) {
|
|
233
|
+
await close().catch(() => void 0);
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
return { close };
|
|
243
237
|
}
|
|
244
238
|
|
|
245
239
|
// src/serve/process.ts
|
|
246
240
|
var STARTUP_MS = 6e4;
|
|
247
|
-
function startAppProcess(appName, options, start) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
return startPrimary(appName, options, workers);
|
|
264
|
-
});
|
|
241
|
+
async function startAppProcess(appName, options, start) {
|
|
242
|
+
var _a;
|
|
243
|
+
const workers = (_a = options.workers) != null ? _a : 1;
|
|
244
|
+
if (!Number.isSafeInteger(workers) || workers < 1) {
|
|
245
|
+
throw new Error("WORKERS must be a positive integer");
|
|
246
|
+
}
|
|
247
|
+
if (workers === 1) {
|
|
248
|
+
const instance = await start(options);
|
|
249
|
+
return { close: () => instance.close() };
|
|
250
|
+
}
|
|
251
|
+
const metrics = getProcessMetrics();
|
|
252
|
+
metrics.startRuntime(appName);
|
|
253
|
+
if (cluster.isWorker) {
|
|
254
|
+
return startWorker(appName, () => start({ ...options, gracefulShutdown: false, ops: false }));
|
|
255
|
+
}
|
|
256
|
+
return startPrimary(appName, options, workers);
|
|
265
257
|
}
|
|
266
|
-
function startPrimary(appName, options, workers) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
258
|
+
async function startPrimary(appName, options, workers) {
|
|
259
|
+
const aggregation = clusterMetrics();
|
|
260
|
+
const logger2 = log3.getLogger(appName).getLogger("cluster");
|
|
261
|
+
const children = /* @__PURE__ */ new Set();
|
|
262
|
+
const alive = /* @__PURE__ */ new Map();
|
|
263
|
+
let ops;
|
|
264
|
+
let closing;
|
|
265
|
+
let started = false;
|
|
266
|
+
let resolveReady = () => void 0;
|
|
267
|
+
let rejectReady = () => void 0;
|
|
268
|
+
const ready = new Promise((resolve, reject) => {
|
|
269
|
+
resolveReady = resolve;
|
|
270
|
+
rejectReady = reject;
|
|
271
|
+
});
|
|
272
|
+
void ready.catch(() => void 0);
|
|
273
|
+
const timeout = setTimeout(() => rejectReady(new Error("Den workers startup timeout")), STARTUP_MS);
|
|
274
|
+
const onMessage = (worker, message) => {
|
|
275
|
+
if (children.has(worker) && typeof message === "object" && message !== null && "type" in message && message.type === ALIVE) {
|
|
276
|
+
alive.set(worker.id, Date.now());
|
|
277
|
+
if (alive.size === workers) resolveReady();
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const close = () => {
|
|
281
|
+
closing != null ? closing : closing = (async () => {
|
|
282
|
+
clearTimeout(timeout);
|
|
283
|
+
resolveReady();
|
|
284
|
+
cluster.removeListener("message", onMessage);
|
|
285
|
+
await Promise.all([...children].map(stopWorker));
|
|
286
|
+
if (ops) await closeHttpServer(ops);
|
|
287
|
+
await aggregation.shutdown();
|
|
288
|
+
for (const signal of SIGNALS) process.removeListener(signal, shutdown);
|
|
289
|
+
})();
|
|
290
|
+
return closing;
|
|
291
|
+
};
|
|
292
|
+
const shutdown = () => {
|
|
293
|
+
void close().then(() => process.exit()).catch((error) => {
|
|
294
|
+
logger2.error("\u043E\u0441\u0442\u0430\u043D\u043E\u0432\u043A\u0430 \u043A\u043B\u0430\u0441\u0442\u0435\u0440\u0430 \u043D\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043B\u0430\u0441\u044C:", error);
|
|
295
|
+
process.exit(1);
|
|
280
296
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
297
|
+
};
|
|
298
|
+
const failed = (error) => {
|
|
299
|
+
if (closing) return;
|
|
300
|
+
if (!started) {
|
|
301
|
+
rejectReady(error);
|
|
302
|
+
} else {
|
|
303
|
+
logger2.error(error);
|
|
304
|
+
process.exitCode = 1;
|
|
305
|
+
shutdown();
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
cluster.on("message", onMessage);
|
|
309
|
+
if (options.gracefulShutdown !== false) {
|
|
310
|
+
for (const signal of SIGNALS) process.on(signal, shutdown);
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
if (options.ops !== false) {
|
|
314
|
+
const supplied = options.ops;
|
|
315
|
+
ops = await startOpsServer({
|
|
316
|
+
...supplied,
|
|
317
|
+
collect: aggregation.collect,
|
|
318
|
+
contentType: aggregation.contentType,
|
|
319
|
+
isLive: () => {
|
|
320
|
+
var _a;
|
|
321
|
+
return [...children].some((worker) => {
|
|
322
|
+
var _a2;
|
|
323
|
+
return worker.isConnected() && Date.now() - ((_a2 = alive.get(worker.id)) != null ? _a2 : 0) < 1e4;
|
|
324
|
+
}) && ((_a = supplied == null ? void 0 : supplied.isLive) == null ? void 0 : _a.call(supplied)) !== false;
|
|
325
|
+
}
|
|
305
326
|
});
|
|
306
|
-
};
|
|
307
|
-
const failed = (error) => {
|
|
308
|
-
if (closing) return;
|
|
309
|
-
if (!started) {
|
|
310
|
-
rejectReady(error);
|
|
311
|
-
} else {
|
|
312
|
-
logger2.error(error);
|
|
313
|
-
process.exitCode = 1;
|
|
314
|
-
shutdown();
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
cluster.on("message", onMessage);
|
|
318
|
-
if (options.gracefulShutdown !== false) {
|
|
319
|
-
for (const signal of SIGNALS) process.on(signal, shutdown);
|
|
320
327
|
}
|
|
321
|
-
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
ops = yield startOpsServer(__spreadProps(__spreadValues({}, supplied), {
|
|
325
|
-
collect: aggregation.collect,
|
|
326
|
-
contentType: aggregation.contentType,
|
|
327
|
-
isLive: () => {
|
|
328
|
-
var _a;
|
|
329
|
-
return [...children].some((worker) => {
|
|
330
|
-
var _a2;
|
|
331
|
-
return worker.isConnected() && Date.now() - ((_a2 = alive.get(worker.id)) != null ? _a2 : 0) < 1e4;
|
|
332
|
-
}) && ((_a = supplied == null ? void 0 : supplied.isLive) == null ? void 0 : _a.call(supplied)) !== false;
|
|
333
|
-
}
|
|
334
|
-
}));
|
|
335
|
-
}
|
|
336
|
-
if (closing) {
|
|
337
|
-
if (ops) yield closeHttpServer(ops);
|
|
338
|
-
yield closing;
|
|
339
|
-
return { close };
|
|
340
|
-
}
|
|
341
|
-
for (let i = 0; i < workers; i++) {
|
|
342
|
-
const worker = cluster.fork();
|
|
343
|
-
children.add(worker);
|
|
344
|
-
worker.once("error", failed);
|
|
345
|
-
worker.once("exit", (code, signal) => {
|
|
346
|
-
alive.delete(worker.id);
|
|
347
|
-
failed(new Error(`Den worker ${String(worker.process.pid)} exited (${String(code != null ? code : signal)})`));
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
yield ready;
|
|
351
|
-
started = true;
|
|
352
|
-
clearTimeout(timeout);
|
|
353
|
-
if (!closing) logger2.info(`\u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043E \u0432\u043E\u0440\u043A\u0435\u0440\u043E\u0432: ${String(workers)}`);
|
|
328
|
+
if (closing) {
|
|
329
|
+
if (ops) await closeHttpServer(ops);
|
|
330
|
+
await closing;
|
|
354
331
|
return { close };
|
|
355
|
-
} catch (error) {
|
|
356
|
-
yield close();
|
|
357
|
-
throw error;
|
|
358
332
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
worker.once("exit", () => {
|
|
367
|
-
clearTimeout(timeout);
|
|
368
|
-
resolve();
|
|
333
|
+
for (let i = 0; i < workers; i++) {
|
|
334
|
+
const worker = cluster.fork();
|
|
335
|
+
children.add(worker);
|
|
336
|
+
worker.once("error", failed);
|
|
337
|
+
worker.once("exit", (code, signal) => {
|
|
338
|
+
alive.delete(worker.id);
|
|
339
|
+
failed(new Error("Den worker ".concat(String(worker.process.pid), " exited (").concat(String(code != null ? code : signal), ")")));
|
|
369
340
|
});
|
|
370
|
-
|
|
341
|
+
}
|
|
342
|
+
await ready;
|
|
343
|
+
started = true;
|
|
344
|
+
clearTimeout(timeout);
|
|
345
|
+
if (!closing) logger2.info("\u0437\u0430\u043F\u0443\u0449\u0435\u043D\u043E \u0432\u043E\u0440\u043A\u0435\u0440\u043E\u0432: ".concat(String(workers)));
|
|
346
|
+
return { close };
|
|
347
|
+
} catch (error) {
|
|
348
|
+
await close();
|
|
349
|
+
throw error;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
async function stopWorker(worker) {
|
|
353
|
+
if (worker.isDead()) return;
|
|
354
|
+
await new Promise((resolve) => {
|
|
355
|
+
const timeout = setTimeout(() => worker.kill("SIGKILL"), SHUTDOWN_MS);
|
|
356
|
+
worker.once("exit", () => {
|
|
357
|
+
clearTimeout(timeout);
|
|
358
|
+
resolve();
|
|
371
359
|
});
|
|
360
|
+
worker.kill("SIGTERM");
|
|
372
361
|
});
|
|
373
362
|
}
|
|
374
363
|
|
|
@@ -377,70 +366,68 @@ function serveAppProcess(app, options = {}) {
|
|
|
377
366
|
return startAppProcess(app.name, options, (serveOptions) => serveApp(app, serveOptions));
|
|
378
367
|
}
|
|
379
368
|
var SHUTDOWN_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
380
|
-
function serveApp(
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
metrics.trackHttp(req.raw, reply.raw, () => {
|
|
398
|
-
var _a2;
|
|
399
|
-
return (_a2 = req.routeOptions.url) != null ? _a2 : "unmatched";
|
|
400
|
-
});
|
|
401
|
-
done();
|
|
402
|
-
});
|
|
403
|
-
instance.addHook("onClose", () => __async(null, null, function* () {
|
|
404
|
-
for (const signal of SHUTDOWN_SIGNALS) {
|
|
405
|
-
process.removeListener(signal, shutdown);
|
|
406
|
-
}
|
|
407
|
-
if (ops) {
|
|
408
|
-
yield closeHttpServer(ops);
|
|
409
|
-
}
|
|
410
|
-
}));
|
|
411
|
-
yield instance.register(appPlugin, { app, slowRenderMs: options.slowRenderMs });
|
|
412
|
-
if (options.assets) {
|
|
413
|
-
registerAssets(instance, options.assets);
|
|
369
|
+
async function serveApp(app, options = {}) {
|
|
370
|
+
var _a, _b, _c, _d, _e;
|
|
371
|
+
const appLog = (_a = log4.getLogger(app.name)) != null ? _a : logger;
|
|
372
|
+
const serveLog = (_b = appLog.getLogger("serve")) != null ? _b : appLog;
|
|
373
|
+
const instance = Fastify({ logger: false });
|
|
374
|
+
const metrics = getProcessMetrics();
|
|
375
|
+
metrics.startRuntime(app.name);
|
|
376
|
+
let ops;
|
|
377
|
+
const shutdown = () => {
|
|
378
|
+
void instance.close();
|
|
379
|
+
};
|
|
380
|
+
instance.addHook("onRequest", (req, reply, done) => {
|
|
381
|
+
if (isOpsPath(req.url)) {
|
|
382
|
+
void reply.code(404).send();
|
|
383
|
+
return;
|
|
414
384
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
});
|
|
419
|
-
instance.addHook("onResponse", (req, reply, done) => {
|
|
420
|
-
const elapsed = reply.elapsedTime.toFixed(1);
|
|
421
|
-
serveLog.info(`\u2190 ${String(reply.statusCode)} ${req.method} ${req.url} ${elapsed}\u043C\u0441`);
|
|
422
|
-
done();
|
|
385
|
+
metrics.trackHttp(req.raw, reply.raw, () => {
|
|
386
|
+
var _a2;
|
|
387
|
+
return (_a2 = req.routeOptions.url) != null ? _a2 : "unmatched";
|
|
423
388
|
});
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
yield instance.listen({ host: (_d = options.host) != null ? _d : "0.0.0.0", port: (_e = options.port) != null ? _e : 8080 });
|
|
430
|
-
} catch (error) {
|
|
431
|
-
yield instance.close();
|
|
432
|
-
throw error;
|
|
389
|
+
done();
|
|
390
|
+
});
|
|
391
|
+
instance.addHook("onClose", async () => {
|
|
392
|
+
for (const signal of SHUTDOWN_SIGNALS) {
|
|
393
|
+
process.removeListener(signal, shutdown);
|
|
433
394
|
}
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
process.once(signal, shutdown);
|
|
437
|
-
}
|
|
395
|
+
if (ops) {
|
|
396
|
+
await closeHttpServer(ops);
|
|
438
397
|
}
|
|
439
|
-
serveLog.info(
|
|
440
|
-
`\u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \xAB${app.name}\xBB \u0441\u043B\u0443\u0448\u0430\u0435\u0442 ${instance.addresses().map((a) => String(a.port)).join(", ")}`
|
|
441
|
-
);
|
|
442
|
-
return instance;
|
|
443
398
|
});
|
|
399
|
+
await instance.register(appPlugin, { app, slowRenderMs: options.slowRenderMs });
|
|
400
|
+
if (options.assets) {
|
|
401
|
+
registerAssets(instance, options.assets);
|
|
402
|
+
}
|
|
403
|
+
instance.addHook("onRequest", (req, _reply, done) => {
|
|
404
|
+
serveLog.debug("\u2192 ".concat(req.method, " ").concat(req.url));
|
|
405
|
+
done();
|
|
406
|
+
});
|
|
407
|
+
instance.addHook("onResponse", (req, reply, done) => {
|
|
408
|
+
const elapsed = reply.elapsedTime.toFixed(1);
|
|
409
|
+
serveLog.info("\u2190 ".concat(String(reply.statusCode), " ").concat(req.method, " ").concat(req.url, " ").concat(elapsed, "\u043C\u0441"));
|
|
410
|
+
done();
|
|
411
|
+
});
|
|
412
|
+
try {
|
|
413
|
+
await ((_c = options.configure) == null ? void 0 : _c.call(options, instance));
|
|
414
|
+
if (options.ops !== false) {
|
|
415
|
+
ops = await startOpsServer(options.ops);
|
|
416
|
+
}
|
|
417
|
+
await instance.listen({ host: (_d = options.host) != null ? _d : "0.0.0.0", port: (_e = options.port) != null ? _e : 8080 });
|
|
418
|
+
} catch (error) {
|
|
419
|
+
await instance.close();
|
|
420
|
+
throw error;
|
|
421
|
+
}
|
|
422
|
+
if (options.gracefulShutdown !== false) {
|
|
423
|
+
for (const signal of SHUTDOWN_SIGNALS) {
|
|
424
|
+
process.once(signal, shutdown);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
serveLog.info(
|
|
428
|
+
"\u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \xAB".concat(app.name, "\xBB \u0441\u043B\u0443\u0448\u0430\u0435\u0442 ").concat(instance.addresses().map((a) => String(a.port)).join(", "))
|
|
429
|
+
);
|
|
430
|
+
return instance;
|
|
444
431
|
}
|
|
445
432
|
export {
|
|
446
433
|
appPlugin,
|
package/chunk-6FNC3XMI.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export {
|
|
42
|
-
__spreadValues,
|
|
43
|
-
__spreadProps,
|
|
44
|
-
__async
|
|
45
|
-
};
|