express-file-cluster 0.1.5 → 0.1.8
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/auth/index.cjs +13 -96
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.d.cts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +7 -51
- package/dist/auth/index.js.map +1 -1
- package/dist/chunk-M7UOT4ZR.js +60 -0
- package/dist/chunk-M7UOT4ZR.js.map +1 -0
- package/dist/chunk-MQNVNOH5.cjs +48 -0
- package/dist/chunk-MQNVNOH5.cjs.map +1 -0
- package/dist/chunk-MZPG5HXL.js +48 -0
- package/dist/chunk-MZPG5HXL.js.map +1 -0
- package/dist/chunk-PFJWEU4E.cjs +60 -0
- package/dist/chunk-PFJWEU4E.cjs.map +1 -0
- package/dist/chunk-UDE6S53C.cjs +42 -0
- package/dist/chunk-UDE6S53C.cjs.map +1 -0
- package/dist/chunk-Z5YNIVQG.js +42 -0
- package/dist/chunk-Z5YNIVQG.js.map +1 -0
- package/dist/cli/index.cjs +101 -167
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +16 -59
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +117 -194
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +46 -79
- package/dist/index.js.map +1 -1
- package/dist/tasks/index.cjs +13 -68
- package/dist/tasks/index.cjs.map +1 -1
- package/dist/tasks/index.d.cts +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.js +7 -33
- package/dist/tasks/index.js.map +1 -1
- package/dist/{types-CkpRAA3y.d.cts → types-Dj9-sLOK.d.cts} +1 -1
- package/dist/{types-CkpRAA3y.d.ts → types-Dj9-sLOK.d.ts} +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,96 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
HttpError: () => HttpError,
|
|
34
|
-
compose: () => compose,
|
|
35
|
-
db: () => db,
|
|
36
|
-
defineModel: () => defineModel,
|
|
37
|
-
getDbClient: () => getDbClient,
|
|
38
|
-
gracefulShutdown: () => gracefulShutdown,
|
|
39
|
-
ignite: () => ignite,
|
|
40
|
-
scanDir: () => scanDir,
|
|
41
|
-
setDbClient: () => setDbClient
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(src_exports);
|
|
44
|
-
var import_express = __toESM(require("express"), 1);
|
|
45
|
-
var import_cors = __toESM(require("cors"), 1);
|
|
46
|
-
var import_cookie_parser = __toESM(require("cookie-parser"), 1);
|
|
47
|
-
var import_node_cluster2 = __toESM(require("cluster"), 1);
|
|
48
|
-
var import_node_os2 = __toESM(require("os"), 1);
|
|
49
|
-
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
3
|
+
var _chunkPFJWEU4Ecjs = require('./chunk-PFJWEU4E.cjs');
|
|
50
4
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
while ((match = re.exec(relativePath)) !== null) {
|
|
67
|
-
if (match[1]) params.push(match[1]);
|
|
68
|
-
}
|
|
69
|
-
return params;
|
|
70
|
-
}
|
|
71
|
-
function scanDir(dir, base = dir) {
|
|
72
|
-
if (!import_node_fs.default.existsSync(dir)) return [];
|
|
73
|
-
const entries = [];
|
|
74
|
-
const items = import_node_fs.default.readdirSync(dir, { withFileTypes: true });
|
|
75
|
-
for (const item of items) {
|
|
76
|
-
const fullPath = import_node_path.default.join(dir, item.name);
|
|
77
|
-
if (item.isDirectory()) {
|
|
78
|
-
entries.push(...scanDir(fullPath, base));
|
|
79
|
-
} else if (ROUTE_FILE_RE.test(item.name)) {
|
|
80
|
-
const relative = "/" + import_node_path.default.relative(base, fullPath).replace(/\\/g, "/");
|
|
81
|
-
entries.push({
|
|
82
|
-
urlPath: filePathToUrlPath(relative),
|
|
83
|
-
filePath: fullPath,
|
|
84
|
-
params: extractParams(relative)
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return entries.sort((a, b) => {
|
|
89
|
-
const aDynamic = a.urlPath.includes(":") ? 1 : 0;
|
|
90
|
-
const bDynamic = b.urlPath.includes(":") ? 1 : 0;
|
|
91
|
-
return aDynamic - bDynamic || a.urlPath.localeCompare(b.urlPath);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkUDE6S53Ccjs = require('./chunk-UDE6S53C.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkMQNVNOH5cjs = require('./chunk-MQNVNOH5.cjs');
|
|
12
|
+
|
|
13
|
+
// src/index.ts
|
|
14
|
+
var _express = require('express'); var _express2 = _interopRequireDefault(_express);
|
|
15
|
+
var _cors = require('cors'); var _cors2 = _interopRequireDefault(_cors);
|
|
16
|
+
var _cookieparser = require('cookie-parser'); var _cookieparser2 = _interopRequireDefault(_cookieparser);
|
|
17
|
+
var _cluster = require('cluster'); var _cluster2 = _interopRequireDefault(_cluster);
|
|
18
|
+
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
19
|
+
var _dotenv = require('dotenv'); var _dotenv2 = _interopRequireDefault(_dotenv);
|
|
94
20
|
|
|
95
21
|
// src/router/mount.ts
|
|
96
22
|
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
@@ -101,7 +27,7 @@ function asyncWrap(handler) {
|
|
|
101
27
|
}
|
|
102
28
|
async function mountRoutes(app, routes) {
|
|
103
29
|
for (const route of routes) {
|
|
104
|
-
const mod = await
|
|
30
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(route.filePath)));
|
|
105
31
|
const routeMiddlewares = Array.isArray(mod["middlewares"]) ? mod["middlewares"] : [];
|
|
106
32
|
const implemented = [];
|
|
107
33
|
const unimplemented = [];
|
|
@@ -131,40 +57,46 @@ async function mountRoutes(app, routes) {
|
|
|
131
57
|
}
|
|
132
58
|
|
|
133
59
|
// src/cluster/index.ts
|
|
134
|
-
|
|
135
|
-
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
var isShuttingDown = false;
|
|
63
|
+
function shutdownMaster() {
|
|
64
|
+
isShuttingDown = true;
|
|
65
|
+
console.log("[EFC] Cluster master shutting down, waiting for workers\u2026");
|
|
66
|
+
}
|
|
136
67
|
function runMaster(options = {}) {
|
|
137
|
-
const count = options.workers
|
|
68
|
+
const count = _nullishCoalesce(options.workers, () => ( _os2.default.cpus().length));
|
|
138
69
|
console.log(`[EFC] Primary ${process.pid} starting ${count} workers`);
|
|
139
70
|
for (let i = 0; i < count; i++) {
|
|
140
|
-
|
|
71
|
+
_cluster2.default.fork();
|
|
141
72
|
}
|
|
142
|
-
|
|
143
|
-
options.onWorkerReady
|
|
73
|
+
_cluster2.default.on("online", (worker) => {
|
|
74
|
+
_optionalChain([options, 'access', _ => _.onWorkerReady, 'optionalCall', _2 => _2(worker.id)]);
|
|
144
75
|
});
|
|
145
|
-
|
|
146
|
-
const exitCode = code
|
|
76
|
+
_cluster2.default.on("exit", (worker, code, signal) => {
|
|
77
|
+
const exitCode = _nullishCoalesce(code, () => ( (signal ? -1 : 0)));
|
|
78
|
+
if (isShuttingDown) {
|
|
79
|
+
console.log(`[EFC] Worker ${worker.id} gracefully exited`);
|
|
80
|
+
if (Object.keys(_nullishCoalesce(_cluster2.default.workers, () => ( {}))).length === 0) {
|
|
81
|
+
console.log("[EFC] All workers exited. Primary exiting.");
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
147
86
|
console.warn(`[EFC] Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
|
|
148
|
-
options.onWorkerCrash
|
|
149
|
-
|
|
87
|
+
_optionalChain([options, 'access', _3 => _3.onWorkerCrash, 'optionalCall', _4 => _4(worker.id, exitCode)]);
|
|
88
|
+
_cluster2.default.fork();
|
|
150
89
|
});
|
|
151
90
|
}
|
|
152
91
|
|
|
153
|
-
// src/auth/index.ts
|
|
154
|
-
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
155
|
-
var _config = null;
|
|
156
|
-
function configureAuth(config) {
|
|
157
|
-
_config = config;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
92
|
// src/db/mongo.ts
|
|
161
93
|
var mongoose;
|
|
162
94
|
async function loadMongoose() {
|
|
163
95
|
if (mongoose) return mongoose;
|
|
164
96
|
try {
|
|
165
|
-
mongoose = await
|
|
97
|
+
mongoose = await Promise.resolve().then(() => _interopRequireWildcard(require("mongoose")));
|
|
166
98
|
return mongoose;
|
|
167
|
-
} catch {
|
|
99
|
+
} catch (e) {
|
|
168
100
|
throw new Error(
|
|
169
101
|
"[EFC] mongoose is not installed. Run: npm install mongoose"
|
|
170
102
|
);
|
|
@@ -185,8 +117,9 @@ function normalise(doc) {
|
|
|
185
117
|
async function getModel(name, schemaObj) {
|
|
186
118
|
let mg;
|
|
187
119
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
120
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("mongoose")));
|
|
121
|
+
mg = mod.default || mod;
|
|
122
|
+
} catch (e2) {
|
|
190
123
|
throw new Error("[EFC] mongoose is not installed. Run: npm install mongoose");
|
|
191
124
|
}
|
|
192
125
|
if (mg.models[name]) return mg.models[name];
|
|
@@ -288,34 +221,22 @@ var db = new Proxy({}, {
|
|
|
288
221
|
});
|
|
289
222
|
|
|
290
223
|
// src/tasks/scanner.ts
|
|
291
|
-
var
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
// src/tasks/index.ts
|
|
295
|
-
var taskRegistry = /* @__PURE__ */ new Map();
|
|
296
|
-
var _impl = null;
|
|
297
|
-
function setEnqueueImpl(impl) {
|
|
298
|
-
_impl = impl;
|
|
299
|
-
}
|
|
300
|
-
function registerTask(name, def) {
|
|
301
|
-
taskRegistry.set(name, { ...def, name });
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// src/tasks/scanner.ts
|
|
224
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
225
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
305
226
|
async function scanTasks(tasksDir) {
|
|
306
|
-
if (!
|
|
307
|
-
const files =
|
|
227
|
+
if (!_fs2.default.existsSync(tasksDir)) return;
|
|
228
|
+
const files = _fs2.default.readdirSync(tasksDir).filter((f) => /\.(ts|js|mts|mjs)$/.test(f));
|
|
308
229
|
for (const file of files) {
|
|
309
|
-
const filePath =
|
|
310
|
-
const taskName =
|
|
230
|
+
const filePath = _path2.default.join(tasksDir, file);
|
|
231
|
+
const taskName = _path2.default.basename(file, _path2.default.extname(file));
|
|
311
232
|
try {
|
|
312
|
-
const mod = await
|
|
233
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(filePath)));
|
|
313
234
|
const def = mod["default"];
|
|
314
235
|
if (!def || typeof def.handler !== "function") {
|
|
315
236
|
console.warn(`[EFC] Task file ${file} has no valid default export \u2014 skipping`);
|
|
316
237
|
continue;
|
|
317
238
|
}
|
|
318
|
-
registerTask(taskName, { ...def, filePath });
|
|
239
|
+
_chunkUDE6S53Ccjs.registerTask.call(void 0, taskName, { ...def, filePath });
|
|
319
240
|
console.log(`[EFC] Registered task: ${taskName}`);
|
|
320
241
|
} catch (err) {
|
|
321
242
|
console.warn(`[EFC] Failed to load task ${file}:`, err);
|
|
@@ -324,32 +245,31 @@ async function scanTasks(tasksDir) {
|
|
|
324
245
|
}
|
|
325
246
|
|
|
326
247
|
// src/tasks/thread-runner.ts
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
const { handlerPath, payload } = import_node_worker_threads.workerData;
|
|
248
|
+
var _worker_threads = require('worker_threads');
|
|
249
|
+
if (!_worker_threads.isMainThread) {
|
|
250
|
+
const { handlerPath, payload } = _worker_threads.workerData;
|
|
331
251
|
(async () => {
|
|
332
252
|
try {
|
|
333
|
-
const mod = await
|
|
253
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(handlerPath)));
|
|
334
254
|
const def = mod["default"];
|
|
335
255
|
if (!def || typeof def.handler !== "function") {
|
|
336
256
|
throw new Error(`[EFC] Thread runner: no valid task export in ${handlerPath}`);
|
|
337
257
|
}
|
|
338
258
|
await def.handler(payload);
|
|
339
|
-
|
|
259
|
+
_optionalChain([_worker_threads.parentPort, 'optionalAccess', _5 => _5.postMessage, 'call', _6 => _6({ ok: true })]);
|
|
340
260
|
} catch (err) {
|
|
341
|
-
|
|
261
|
+
_optionalChain([_worker_threads.parentPort, 'optionalAccess', _7 => _7.postMessage, 'call', _8 => _8({ ok: false, error: String(err) })]);
|
|
342
262
|
}
|
|
343
263
|
})();
|
|
344
264
|
}
|
|
345
265
|
function runInThread(handlerPath, payload) {
|
|
346
266
|
return new Promise((resolve, reject) => {
|
|
347
|
-
const worker = new
|
|
267
|
+
const worker = new (0, _worker_threads.Worker)(new URL("./thread-runner.js", import.meta.url), {
|
|
348
268
|
workerData: { handlerPath, payload }
|
|
349
269
|
});
|
|
350
270
|
worker.on("message", (msg) => {
|
|
351
271
|
if (msg.ok) resolve();
|
|
352
|
-
else reject(new Error(msg.error
|
|
272
|
+
else reject(new Error(_nullishCoalesce(msg.error, () => ( "Thread task failed"))));
|
|
353
273
|
});
|
|
354
274
|
worker.on("error", reject);
|
|
355
275
|
worker.on("exit", (code) => {
|
|
@@ -362,8 +282,8 @@ function runInThread(handlerPath, payload) {
|
|
|
362
282
|
async function initBullMQ(opts) {
|
|
363
283
|
let bullmq;
|
|
364
284
|
try {
|
|
365
|
-
bullmq = await
|
|
366
|
-
} catch {
|
|
285
|
+
bullmq = await Promise.resolve().then(() => _interopRequireWildcard(require("bullmq")));
|
|
286
|
+
} catch (e3) {
|
|
367
287
|
throw new Error("[EFC] bullmq is not installed. Run: npm install bullmq");
|
|
368
288
|
}
|
|
369
289
|
const connection = parseRedisUrl(opts.redisUrl);
|
|
@@ -371,7 +291,7 @@ async function initBullMQ(opts) {
|
|
|
371
291
|
const worker = new bullmq.Worker(
|
|
372
292
|
"efc",
|
|
373
293
|
async (job) => {
|
|
374
|
-
const def = taskRegistry.get(job.name);
|
|
294
|
+
const def = _chunkUDE6S53Ccjs.taskRegistry.get(job.name);
|
|
375
295
|
if (!def) {
|
|
376
296
|
throw new Error(`[EFC] No task registered for name: ${job.name}`);
|
|
377
297
|
}
|
|
@@ -384,20 +304,20 @@ async function initBullMQ(opts) {
|
|
|
384
304
|
{ connection, concurrency: opts.concurrency }
|
|
385
305
|
);
|
|
386
306
|
worker.on("failed", (job, err) => {
|
|
387
|
-
console.error(`[EFC] Task ${job
|
|
307
|
+
console.error(`[EFC] Task ${_nullishCoalesce(_optionalChain([job, 'optionalAccess', _9 => _9.name]), () => ( "unknown"))} failed:`, err.message);
|
|
388
308
|
});
|
|
389
309
|
worker.on("completed", (job) => {
|
|
390
310
|
console.log(`[EFC] Task ${job.name} completed (id=${job.id})`);
|
|
391
311
|
});
|
|
392
|
-
setEnqueueImpl(async (name, payload) => {
|
|
393
|
-
const def = taskRegistry.get(name);
|
|
312
|
+
_chunkUDE6S53Ccjs.setEnqueueImpl.call(void 0, async (name, payload) => {
|
|
313
|
+
const def = _chunkUDE6S53Ccjs.taskRegistry.get(name);
|
|
394
314
|
if (!def) {
|
|
395
315
|
throw new Error(`[EFC] Cannot enqueue unknown task: "${name}". Is the task file in tasksDir?`);
|
|
396
316
|
}
|
|
397
317
|
await queue.add(name, payload, {
|
|
398
|
-
attempts: def.options.retries
|
|
318
|
+
attempts: _nullishCoalesce(def.options.retries, () => ( 3)),
|
|
399
319
|
backoff: {
|
|
400
|
-
type: def.options.backoff
|
|
320
|
+
type: _nullishCoalesce(def.options.backoff, () => ( "exponential")),
|
|
401
321
|
delay: 1e3
|
|
402
322
|
}
|
|
403
323
|
});
|
|
@@ -413,14 +333,14 @@ function parseRedisUrl(url) {
|
|
|
413
333
|
};
|
|
414
334
|
if (u.password) result.password = u.password;
|
|
415
335
|
return result;
|
|
416
|
-
} catch {
|
|
336
|
+
} catch (e4) {
|
|
417
337
|
return { host: "localhost", port: 6379 };
|
|
418
338
|
}
|
|
419
339
|
}
|
|
420
340
|
|
|
421
341
|
// src/errors.ts
|
|
422
342
|
var HttpError = class _HttpError extends Error {
|
|
423
|
-
|
|
343
|
+
|
|
424
344
|
constructor(statusCode, message) {
|
|
425
345
|
super(message);
|
|
426
346
|
this.name = "HttpError";
|
|
@@ -455,7 +375,7 @@ function compose(...handlers) {
|
|
|
455
375
|
|
|
456
376
|
// src/index.ts
|
|
457
377
|
if (process.env["NODE_ENV"] !== "production") {
|
|
458
|
-
|
|
378
|
+
_dotenv2.default.config();
|
|
459
379
|
}
|
|
460
380
|
function detectDatabase(url) {
|
|
461
381
|
if (!url) return void 0;
|
|
@@ -475,21 +395,21 @@ async function ignite(config) {
|
|
|
475
395
|
} = config;
|
|
476
396
|
const envPort = process.env["PORT"] != null ? Number(process.env["PORT"]) : NaN;
|
|
477
397
|
const port = _port != null && !Number.isNaN(_port) ? _port : !Number.isNaN(envPort) ? envPort : 3e3;
|
|
478
|
-
const databaseUrl = config.databaseUrl
|
|
479
|
-
const database = config.database
|
|
480
|
-
const jwtSecret = config.jwtSecret
|
|
481
|
-
const authStrategy = config.authStrategy
|
|
482
|
-
const clusterEnabled = config.cluster
|
|
483
|
-
if (clusterEnabled &&
|
|
398
|
+
const databaseUrl = _nullishCoalesce(config.databaseUrl, () => ( process.env["DATABASE_URL"]));
|
|
399
|
+
const database = _nullishCoalesce(config.database, () => ( detectDatabase(databaseUrl)));
|
|
400
|
+
const jwtSecret = _nullishCoalesce(config.jwtSecret, () => ( process.env["JWT_SECRET"]));
|
|
401
|
+
const authStrategy = _nullishCoalesce(config.authStrategy, () => ( "http-only"));
|
|
402
|
+
const clusterEnabled = _nullishCoalesce(config.cluster, () => ( process.env["NODE_ENV"] === "production"));
|
|
403
|
+
if (clusterEnabled && _cluster2.default.isPrimary) {
|
|
484
404
|
runMaster({
|
|
485
|
-
workers: workers
|
|
405
|
+
workers: _nullishCoalesce(workers, () => ( _os2.default.cpus().length)),
|
|
486
406
|
...onWorkerReady !== void 0 && { onWorkerReady },
|
|
487
407
|
...onWorkerCrash !== void 0 && { onWorkerCrash }
|
|
488
408
|
});
|
|
489
409
|
return;
|
|
490
410
|
}
|
|
491
|
-
const app = (0,
|
|
492
|
-
const corsOption = config.cors
|
|
411
|
+
const app = _express2.default.call(void 0, );
|
|
412
|
+
const corsOption = _nullishCoalesce(config.cors, () => ( true));
|
|
493
413
|
if (corsOption !== false) {
|
|
494
414
|
const envOrigins = process.env["CORS_ORIGINS"];
|
|
495
415
|
let origin;
|
|
@@ -502,11 +422,11 @@ async function ignite(config) {
|
|
|
502
422
|
origin = true;
|
|
503
423
|
}
|
|
504
424
|
const corsOpts = typeof corsOption === "object" ? { ...corsOption, origin } : { origin };
|
|
505
|
-
app.use((0,
|
|
425
|
+
app.use(_cors2.default.call(void 0, corsOpts));
|
|
506
426
|
}
|
|
507
|
-
app.use(
|
|
508
|
-
app.use(
|
|
509
|
-
app.use((0,
|
|
427
|
+
app.use(_express2.default.json());
|
|
428
|
+
app.use(_express2.default.urlencoded({ extended: true }));
|
|
429
|
+
app.use(_cookieparser2.default.call(void 0, ));
|
|
510
430
|
for (const mw of globalMiddlewares) {
|
|
511
431
|
app.use(mw);
|
|
512
432
|
}
|
|
@@ -516,10 +436,10 @@ async function ignite(config) {
|
|
|
516
436
|
}
|
|
517
437
|
if (jwtSecret) {
|
|
518
438
|
const cookieDomain = process.env["COOKIE_DOMAIN"];
|
|
519
|
-
configureAuth({
|
|
439
|
+
_chunkPFJWEU4Ecjs.configureAuth.call(void 0, {
|
|
520
440
|
secret: jwtSecret,
|
|
521
441
|
strategy: authStrategy,
|
|
522
|
-
expiresIn: process.env["JWT_EXPIRES_IN"]
|
|
442
|
+
expiresIn: _nullishCoalesce(process.env["JWT_EXPIRES_IN"], () => ( "7d")),
|
|
523
443
|
...cookieDomain !== void 0 && { cookieDomain }
|
|
524
444
|
});
|
|
525
445
|
}
|
|
@@ -529,12 +449,12 @@ async function ignite(config) {
|
|
|
529
449
|
if (config.tasks) {
|
|
530
450
|
if (config.tasks.backend === "bullmq") {
|
|
531
451
|
await initBullMQ({
|
|
532
|
-
redisUrl: config.tasks.redisUrl
|
|
533
|
-
concurrency: config.tasks.concurrency
|
|
452
|
+
redisUrl: _nullishCoalesce(config.tasks.redisUrl, () => ( "redis://localhost:6379")),
|
|
453
|
+
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5))
|
|
534
454
|
});
|
|
535
455
|
}
|
|
536
456
|
}
|
|
537
|
-
const routes = scanDir(apiDir);
|
|
457
|
+
const routes = _chunkMQNVNOH5cjs.scanDir.call(void 0, apiDir);
|
|
538
458
|
await mountRoutes(app, routes);
|
|
539
459
|
if (onError) {
|
|
540
460
|
app.use(onError);
|
|
@@ -554,9 +474,9 @@ async function ignite(config) {
|
|
|
554
474
|
return new Promise((resolve, reject) => {
|
|
555
475
|
const server = app.listen(port);
|
|
556
476
|
server.once("listening", () => {
|
|
557
|
-
const wid =
|
|
477
|
+
const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _10 => _10.worker, 'optionalAccess', _11 => _11.id]), () => ( "primary"));
|
|
558
478
|
const addr = server.address();
|
|
559
|
-
console.log(`[EFC] Worker ${wid} listening on :${addr
|
|
479
|
+
console.log(`[EFC] Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _12 => _12.port]), () => ( port))}`);
|
|
560
480
|
resolve(server);
|
|
561
481
|
});
|
|
562
482
|
server.once("error", reject);
|
|
@@ -565,29 +485,32 @@ async function ignite(config) {
|
|
|
565
485
|
function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
566
486
|
const shutdown = (signal) => {
|
|
567
487
|
console.log(`[EFC] ${signal} received \u2014 closing server gracefully\u2026`);
|
|
568
|
-
server
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
488
|
+
if (server) {
|
|
489
|
+
server.closeIdleConnections();
|
|
490
|
+
server.close(() => {
|
|
491
|
+
console.log("[EFC] Server closed");
|
|
492
|
+
process.exit(0);
|
|
493
|
+
});
|
|
494
|
+
setTimeout(() => {
|
|
495
|
+
console.error("[EFC] Forced exit after timeout");
|
|
496
|
+
process.exit(1);
|
|
497
|
+
}, timeoutMs).unref();
|
|
498
|
+
} else {
|
|
499
|
+
shutdownMaster();
|
|
500
|
+
}
|
|
577
501
|
};
|
|
578
502
|
process.once("SIGTERM", () => shutdown("SIGTERM"));
|
|
579
503
|
process.once("SIGINT", () => shutdown("SIGINT"));
|
|
580
504
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
});
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
exports.HttpError = HttpError; exports.compose = compose; exports.db = db; exports.defineModel = defineModel; exports.getDbClient = getDbClient; exports.gracefulShutdown = gracefulShutdown; exports.ignite = ignite; exports.scanDir = _chunkMQNVNOH5cjs.scanDir; exports.setDbClient = setDbClient;
|
|
593
516
|
//# sourceMappingURL=index.cjs.map
|