@foxford/den 4.0.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 +43 -4
- 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-2P5TAWRW.cjs → chunk-MH2WIOTQ.cjs} +65 -60
- package/{chunk-XOJ2VWX4.cjs → chunk-MWDNN7Q4.cjs} +1 -1
- package/{chunk-QTWJTYZW.cjs → chunk-NOI7FSBX.cjs} +47 -55
- package/{chunk-DUU4MQ4B.js → chunk-VCIMVMHG.js} +64 -59
- 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 +294 -108
- package/serve/index.d.cts +11 -1
- package/serve/index.d.ts +11 -1
- package/serve/index.js +293 -107
- package/chunk-6FNC3XMI.js +0 -45
- package/chunk-FMRORLLE.js +0 -558
- package/chunk-OC4LQ2CK.cjs +0 -558
- package/chunk-T5QVCXVB.cjs +0 -45
package/serve/index.js
CHANGED
|
@@ -6,26 +6,23 @@ 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
|
|
14
14
|
} from "../chunk-TPBI6TOU.js";
|
|
15
15
|
import {
|
|
16
16
|
closeHttpServer,
|
|
17
|
+
clusterMetrics,
|
|
17
18
|
getProcessMetrics,
|
|
18
19
|
isOpsPath,
|
|
19
20
|
startOpsServer
|
|
20
|
-
} from "../chunk-
|
|
21
|
-
import {
|
|
22
|
-
__async,
|
|
23
|
-
__spreadValues
|
|
24
|
-
} from "../chunk-6FNC3XMI.js";
|
|
21
|
+
} from "../chunk-VCIMVMHG.js";
|
|
25
22
|
|
|
26
23
|
// src/serve/index.ts
|
|
27
24
|
import Fastify from "fastify";
|
|
28
|
-
import { log as
|
|
25
|
+
import { log as log4 } from "@foxford/logger";
|
|
29
26
|
|
|
30
27
|
// src/serve/assets.ts
|
|
31
28
|
import { createReadStream, existsSync, statSync } from "fs";
|
|
@@ -49,7 +46,7 @@ var MIME = {
|
|
|
49
46
|
var HASHED_DIR = "assets/";
|
|
50
47
|
function assetsPrefix(base) {
|
|
51
48
|
const { pathname } = new URL(base, "http://assets.invalid");
|
|
52
|
-
return pathname.endsWith("/") ? pathname :
|
|
49
|
+
return pathname.endsWith("/") ? pathname : "".concat(pathname, "/");
|
|
53
50
|
}
|
|
54
51
|
function assetFile(dir, relative) {
|
|
55
52
|
const file = path.normalize(path.join(dir, relative));
|
|
@@ -58,7 +55,7 @@ function assetFile(dir, relative) {
|
|
|
58
55
|
function registerAssets(instance, source) {
|
|
59
56
|
const dir = path.resolve(source.dir);
|
|
60
57
|
const prefix = assetsPrefix(source.base);
|
|
61
|
-
instance.get(
|
|
58
|
+
instance.get("".concat(prefix, "*"), (request, reply) => {
|
|
62
59
|
var _a;
|
|
63
60
|
const relative = request.params["*"];
|
|
64
61
|
const file = assetFile(dir, relative);
|
|
@@ -98,7 +95,10 @@ function requestContextOf(req, fromBody) {
|
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
const cookie = req.headers.cookie;
|
|
101
|
-
const backendHeaders =
|
|
98
|
+
const backendHeaders = {
|
|
99
|
+
...typeof cookie === "string" && cookie !== "" ? { cookie } : {},
|
|
100
|
+
...fromBody
|
|
101
|
+
};
|
|
102
102
|
return { backendHeaders, cookies: parseCookieHeader(cookie), headers };
|
|
103
103
|
}
|
|
104
104
|
function backendHeadersOf(value) {
|
|
@@ -123,43 +123,41 @@ var appPlugin = (instance, options) => {
|
|
|
123
123
|
void reply.header("cache-control", "no-store");
|
|
124
124
|
return claim(app);
|
|
125
125
|
});
|
|
126
|
-
function handleRender(req, reply, target, inputs, rawBackendHeaders) {
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
serveLog.warn(`\u043C\u0435\u0434\u043B\u0435\u043D\u043D\u044B\u0439 \u0440\u0435\u043D\u0434\u0435\u0440 \xAB${pathname}\xBB: ${String(elapsed)}\u043C\u0441`);
|
|
156
|
-
}
|
|
157
|
-
return result;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
serveLog.error(`\u0440\u0435\u043D\u0434\u0435\u0440 \xAB${pathname}\xBB \u0443\u043F\u0430\u043B \u0437\u0430 ${String(Date.now() - startedAt)}\u043C\u0441`, error);
|
|
160
|
-
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"));
|
|
161
155
|
}
|
|
162
|
-
|
|
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
|
+
}
|
|
163
161
|
}
|
|
164
162
|
instance.get(
|
|
165
163
|
"/_render",
|
|
@@ -177,76 +175,264 @@ var appPlugin = (instance, options) => {
|
|
|
177
175
|
return Promise.resolve();
|
|
178
176
|
};
|
|
179
177
|
|
|
180
|
-
// src/serve/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
178
|
+
// src/serve/process.ts
|
|
179
|
+
import cluster from "cluster";
|
|
180
|
+
import { log as log3 } from "@foxford/logger";
|
|
181
|
+
|
|
182
|
+
// src/serve/worker.ts
|
|
183
|
+
import { log as log2 } from "@foxford/logger";
|
|
184
|
+
var ALIVE = "den:app-worker-alive";
|
|
185
|
+
var SIGNALS = ["SIGTERM", "SIGINT"];
|
|
186
|
+
var SHUTDOWN_MS = 1e4;
|
|
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 {
|
|
200
|
+
try {
|
|
201
|
+
if (process.connected) await aggregation.shutdown();
|
|
202
|
+
} finally {
|
|
203
|
+
for (const signal of SIGNALS) process.removeListener(signal, shutdown);
|
|
204
|
+
process.removeListener("disconnect", shutdown);
|
|
205
|
+
if (process.connected) process.disconnect();
|
|
206
|
+
}
|
|
198
207
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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);
|
|
204
217
|
});
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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();
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
await close().catch(() => void 0);
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
return { close };
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// src/serve/process.ts
|
|
240
|
+
var STARTUP_MS = 6e4;
|
|
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);
|
|
257
|
+
}
|
|
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);
|
|
220
296
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
if (closing) {
|
|
329
|
+
if (ops) await closeHttpServer(ops);
|
|
330
|
+
await closing;
|
|
331
|
+
return { close };
|
|
332
|
+
}
|
|
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), ")")));
|
|
340
|
+
});
|
|
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();
|
|
225
359
|
});
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
360
|
+
worker.kill("SIGTERM");
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/serve/index.ts
|
|
365
|
+
function serveAppProcess(app, options = {}) {
|
|
366
|
+
return startAppProcess(app.name, options, (serveOptions) => serveApp(app, serveOptions));
|
|
367
|
+
}
|
|
368
|
+
var SHUTDOWN_SIGNALS = ["SIGTERM", "SIGINT"];
|
|
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;
|
|
235
384
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
385
|
+
metrics.trackHttp(req.raw, reply.raw, () => {
|
|
386
|
+
var _a2;
|
|
387
|
+
return (_a2 = req.routeOptions.url) != null ? _a2 : "unmatched";
|
|
388
|
+
});
|
|
389
|
+
done();
|
|
390
|
+
});
|
|
391
|
+
instance.addHook("onClose", async () => {
|
|
392
|
+
for (const signal of SHUTDOWN_SIGNALS) {
|
|
393
|
+
process.removeListener(signal, shutdown);
|
|
240
394
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
395
|
+
if (ops) {
|
|
396
|
+
await closeHttpServer(ops);
|
|
397
|
+
}
|
|
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();
|
|
245
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;
|
|
246
431
|
}
|
|
247
432
|
export {
|
|
248
433
|
appPlugin,
|
|
249
434
|
loadAppEnv,
|
|
250
435
|
registerAssets,
|
|
251
|
-
serveApp
|
|
436
|
+
serveApp,
|
|
437
|
+
serveAppProcess
|
|
252
438
|
};
|
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
|
-
};
|