express-file-cluster 0.1.6 → 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 +92 -186
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -70
- 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,53 +57,46 @@ async function mountRoutes(app, routes) {
|
|
|
131
57
|
}
|
|
132
58
|
|
|
133
59
|
// src/cluster/index.ts
|
|
134
|
-
|
|
135
|
-
|
|
60
|
+
|
|
61
|
+
|
|
136
62
|
var isShuttingDown = false;
|
|
137
63
|
function shutdownMaster() {
|
|
138
64
|
isShuttingDown = true;
|
|
139
65
|
console.log("[EFC] Cluster master shutting down, waiting for workers\u2026");
|
|
140
66
|
}
|
|
141
67
|
function runMaster(options = {}) {
|
|
142
|
-
const count = options.workers
|
|
68
|
+
const count = _nullishCoalesce(options.workers, () => ( _os2.default.cpus().length));
|
|
143
69
|
console.log(`[EFC] Primary ${process.pid} starting ${count} workers`);
|
|
144
70
|
for (let i = 0; i < count; i++) {
|
|
145
|
-
|
|
71
|
+
_cluster2.default.fork();
|
|
146
72
|
}
|
|
147
|
-
|
|
148
|
-
options.onWorkerReady
|
|
73
|
+
_cluster2.default.on("online", (worker) => {
|
|
74
|
+
_optionalChain([options, 'access', _ => _.onWorkerReady, 'optionalCall', _2 => _2(worker.id)]);
|
|
149
75
|
});
|
|
150
|
-
|
|
151
|
-
const exitCode = code
|
|
76
|
+
_cluster2.default.on("exit", (worker, code, signal) => {
|
|
77
|
+
const exitCode = _nullishCoalesce(code, () => ( (signal ? -1 : 0)));
|
|
152
78
|
if (isShuttingDown) {
|
|
153
79
|
console.log(`[EFC] Worker ${worker.id} gracefully exited`);
|
|
154
|
-
if (Object.keys(
|
|
80
|
+
if (Object.keys(_nullishCoalesce(_cluster2.default.workers, () => ( {}))).length === 0) {
|
|
155
81
|
console.log("[EFC] All workers exited. Primary exiting.");
|
|
156
82
|
process.exit(0);
|
|
157
83
|
}
|
|
158
84
|
return;
|
|
159
85
|
}
|
|
160
86
|
console.warn(`[EFC] Worker ${worker.id} exited (code=${exitCode}), respawning\u2026`);
|
|
161
|
-
options.onWorkerCrash
|
|
162
|
-
|
|
87
|
+
_optionalChain([options, 'access', _3 => _3.onWorkerCrash, 'optionalCall', _4 => _4(worker.id, exitCode)]);
|
|
88
|
+
_cluster2.default.fork();
|
|
163
89
|
});
|
|
164
90
|
}
|
|
165
91
|
|
|
166
|
-
// src/auth/index.ts
|
|
167
|
-
var import_jsonwebtoken = __toESM(require("jsonwebtoken"), 1);
|
|
168
|
-
var _config = null;
|
|
169
|
-
function configureAuth(config) {
|
|
170
|
-
_config = config;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
92
|
// src/db/mongo.ts
|
|
174
93
|
var mongoose;
|
|
175
94
|
async function loadMongoose() {
|
|
176
95
|
if (mongoose) return mongoose;
|
|
177
96
|
try {
|
|
178
|
-
mongoose = await
|
|
97
|
+
mongoose = await Promise.resolve().then(() => _interopRequireWildcard(require("mongoose")));
|
|
179
98
|
return mongoose;
|
|
180
|
-
} catch {
|
|
99
|
+
} catch (e) {
|
|
181
100
|
throw new Error(
|
|
182
101
|
"[EFC] mongoose is not installed. Run: npm install mongoose"
|
|
183
102
|
);
|
|
@@ -198,8 +117,9 @@ function normalise(doc) {
|
|
|
198
117
|
async function getModel(name, schemaObj) {
|
|
199
118
|
let mg;
|
|
200
119
|
try {
|
|
201
|
-
|
|
202
|
-
|
|
120
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("mongoose")));
|
|
121
|
+
mg = mod.default || mod;
|
|
122
|
+
} catch (e2) {
|
|
203
123
|
throw new Error("[EFC] mongoose is not installed. Run: npm install mongoose");
|
|
204
124
|
}
|
|
205
125
|
if (mg.models[name]) return mg.models[name];
|
|
@@ -301,34 +221,22 @@ var db = new Proxy({}, {
|
|
|
301
221
|
});
|
|
302
222
|
|
|
303
223
|
// src/tasks/scanner.ts
|
|
304
|
-
var
|
|
305
|
-
var
|
|
306
|
-
|
|
307
|
-
// src/tasks/index.ts
|
|
308
|
-
var taskRegistry = /* @__PURE__ */ new Map();
|
|
309
|
-
var _impl = null;
|
|
310
|
-
function setEnqueueImpl(impl) {
|
|
311
|
-
_impl = impl;
|
|
312
|
-
}
|
|
313
|
-
function registerTask(name, def) {
|
|
314
|
-
taskRegistry.set(name, { ...def, name });
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// src/tasks/scanner.ts
|
|
224
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
225
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
318
226
|
async function scanTasks(tasksDir) {
|
|
319
|
-
if (!
|
|
320
|
-
const files =
|
|
227
|
+
if (!_fs2.default.existsSync(tasksDir)) return;
|
|
228
|
+
const files = _fs2.default.readdirSync(tasksDir).filter((f) => /\.(ts|js|mts|mjs)$/.test(f));
|
|
321
229
|
for (const file of files) {
|
|
322
|
-
const filePath =
|
|
323
|
-
const taskName =
|
|
230
|
+
const filePath = _path2.default.join(tasksDir, file);
|
|
231
|
+
const taskName = _path2.default.basename(file, _path2.default.extname(file));
|
|
324
232
|
try {
|
|
325
|
-
const mod = await
|
|
233
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(filePath)));
|
|
326
234
|
const def = mod["default"];
|
|
327
235
|
if (!def || typeof def.handler !== "function") {
|
|
328
236
|
console.warn(`[EFC] Task file ${file} has no valid default export \u2014 skipping`);
|
|
329
237
|
continue;
|
|
330
238
|
}
|
|
331
|
-
registerTask(taskName, { ...def, filePath });
|
|
239
|
+
_chunkUDE6S53Ccjs.registerTask.call(void 0, taskName, { ...def, filePath });
|
|
332
240
|
console.log(`[EFC] Registered task: ${taskName}`);
|
|
333
241
|
} catch (err) {
|
|
334
242
|
console.warn(`[EFC] Failed to load task ${file}:`, err);
|
|
@@ -337,32 +245,31 @@ async function scanTasks(tasksDir) {
|
|
|
337
245
|
}
|
|
338
246
|
|
|
339
247
|
// src/tasks/thread-runner.ts
|
|
340
|
-
var
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
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;
|
|
344
251
|
(async () => {
|
|
345
252
|
try {
|
|
346
|
-
const mod = await
|
|
253
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(handlerPath)));
|
|
347
254
|
const def = mod["default"];
|
|
348
255
|
if (!def || typeof def.handler !== "function") {
|
|
349
256
|
throw new Error(`[EFC] Thread runner: no valid task export in ${handlerPath}`);
|
|
350
257
|
}
|
|
351
258
|
await def.handler(payload);
|
|
352
|
-
|
|
259
|
+
_optionalChain([_worker_threads.parentPort, 'optionalAccess', _5 => _5.postMessage, 'call', _6 => _6({ ok: true })]);
|
|
353
260
|
} catch (err) {
|
|
354
|
-
|
|
261
|
+
_optionalChain([_worker_threads.parentPort, 'optionalAccess', _7 => _7.postMessage, 'call', _8 => _8({ ok: false, error: String(err) })]);
|
|
355
262
|
}
|
|
356
263
|
})();
|
|
357
264
|
}
|
|
358
265
|
function runInThread(handlerPath, payload) {
|
|
359
266
|
return new Promise((resolve, reject) => {
|
|
360
|
-
const worker = new
|
|
267
|
+
const worker = new (0, _worker_threads.Worker)(new URL("./thread-runner.js", import.meta.url), {
|
|
361
268
|
workerData: { handlerPath, payload }
|
|
362
269
|
});
|
|
363
270
|
worker.on("message", (msg) => {
|
|
364
271
|
if (msg.ok) resolve();
|
|
365
|
-
else reject(new Error(msg.error
|
|
272
|
+
else reject(new Error(_nullishCoalesce(msg.error, () => ( "Thread task failed"))));
|
|
366
273
|
});
|
|
367
274
|
worker.on("error", reject);
|
|
368
275
|
worker.on("exit", (code) => {
|
|
@@ -375,8 +282,8 @@ function runInThread(handlerPath, payload) {
|
|
|
375
282
|
async function initBullMQ(opts) {
|
|
376
283
|
let bullmq;
|
|
377
284
|
try {
|
|
378
|
-
bullmq = await
|
|
379
|
-
} catch {
|
|
285
|
+
bullmq = await Promise.resolve().then(() => _interopRequireWildcard(require("bullmq")));
|
|
286
|
+
} catch (e3) {
|
|
380
287
|
throw new Error("[EFC] bullmq is not installed. Run: npm install bullmq");
|
|
381
288
|
}
|
|
382
289
|
const connection = parseRedisUrl(opts.redisUrl);
|
|
@@ -384,7 +291,7 @@ async function initBullMQ(opts) {
|
|
|
384
291
|
const worker = new bullmq.Worker(
|
|
385
292
|
"efc",
|
|
386
293
|
async (job) => {
|
|
387
|
-
const def = taskRegistry.get(job.name);
|
|
294
|
+
const def = _chunkUDE6S53Ccjs.taskRegistry.get(job.name);
|
|
388
295
|
if (!def) {
|
|
389
296
|
throw new Error(`[EFC] No task registered for name: ${job.name}`);
|
|
390
297
|
}
|
|
@@ -397,20 +304,20 @@ async function initBullMQ(opts) {
|
|
|
397
304
|
{ connection, concurrency: opts.concurrency }
|
|
398
305
|
);
|
|
399
306
|
worker.on("failed", (job, err) => {
|
|
400
|
-
console.error(`[EFC] Task ${job
|
|
307
|
+
console.error(`[EFC] Task ${_nullishCoalesce(_optionalChain([job, 'optionalAccess', _9 => _9.name]), () => ( "unknown"))} failed:`, err.message);
|
|
401
308
|
});
|
|
402
309
|
worker.on("completed", (job) => {
|
|
403
310
|
console.log(`[EFC] Task ${job.name} completed (id=${job.id})`);
|
|
404
311
|
});
|
|
405
|
-
setEnqueueImpl(async (name, payload) => {
|
|
406
|
-
const def = taskRegistry.get(name);
|
|
312
|
+
_chunkUDE6S53Ccjs.setEnqueueImpl.call(void 0, async (name, payload) => {
|
|
313
|
+
const def = _chunkUDE6S53Ccjs.taskRegistry.get(name);
|
|
407
314
|
if (!def) {
|
|
408
315
|
throw new Error(`[EFC] Cannot enqueue unknown task: "${name}". Is the task file in tasksDir?`);
|
|
409
316
|
}
|
|
410
317
|
await queue.add(name, payload, {
|
|
411
|
-
attempts: def.options.retries
|
|
318
|
+
attempts: _nullishCoalesce(def.options.retries, () => ( 3)),
|
|
412
319
|
backoff: {
|
|
413
|
-
type: def.options.backoff
|
|
320
|
+
type: _nullishCoalesce(def.options.backoff, () => ( "exponential")),
|
|
414
321
|
delay: 1e3
|
|
415
322
|
}
|
|
416
323
|
});
|
|
@@ -426,14 +333,14 @@ function parseRedisUrl(url) {
|
|
|
426
333
|
};
|
|
427
334
|
if (u.password) result.password = u.password;
|
|
428
335
|
return result;
|
|
429
|
-
} catch {
|
|
336
|
+
} catch (e4) {
|
|
430
337
|
return { host: "localhost", port: 6379 };
|
|
431
338
|
}
|
|
432
339
|
}
|
|
433
340
|
|
|
434
341
|
// src/errors.ts
|
|
435
342
|
var HttpError = class _HttpError extends Error {
|
|
436
|
-
|
|
343
|
+
|
|
437
344
|
constructor(statusCode, message) {
|
|
438
345
|
super(message);
|
|
439
346
|
this.name = "HttpError";
|
|
@@ -468,7 +375,7 @@ function compose(...handlers) {
|
|
|
468
375
|
|
|
469
376
|
// src/index.ts
|
|
470
377
|
if (process.env["NODE_ENV"] !== "production") {
|
|
471
|
-
|
|
378
|
+
_dotenv2.default.config();
|
|
472
379
|
}
|
|
473
380
|
function detectDatabase(url) {
|
|
474
381
|
if (!url) return void 0;
|
|
@@ -488,21 +395,21 @@ async function ignite(config) {
|
|
|
488
395
|
} = config;
|
|
489
396
|
const envPort = process.env["PORT"] != null ? Number(process.env["PORT"]) : NaN;
|
|
490
397
|
const port = _port != null && !Number.isNaN(_port) ? _port : !Number.isNaN(envPort) ? envPort : 3e3;
|
|
491
|
-
const databaseUrl = config.databaseUrl
|
|
492
|
-
const database = config.database
|
|
493
|
-
const jwtSecret = config.jwtSecret
|
|
494
|
-
const authStrategy = config.authStrategy
|
|
495
|
-
const clusterEnabled = config.cluster
|
|
496
|
-
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) {
|
|
497
404
|
runMaster({
|
|
498
|
-
workers: workers
|
|
405
|
+
workers: _nullishCoalesce(workers, () => ( _os2.default.cpus().length)),
|
|
499
406
|
...onWorkerReady !== void 0 && { onWorkerReady },
|
|
500
407
|
...onWorkerCrash !== void 0 && { onWorkerCrash }
|
|
501
408
|
});
|
|
502
409
|
return;
|
|
503
410
|
}
|
|
504
|
-
const app = (0,
|
|
505
|
-
const corsOption = config.cors
|
|
411
|
+
const app = _express2.default.call(void 0, );
|
|
412
|
+
const corsOption = _nullishCoalesce(config.cors, () => ( true));
|
|
506
413
|
if (corsOption !== false) {
|
|
507
414
|
const envOrigins = process.env["CORS_ORIGINS"];
|
|
508
415
|
let origin;
|
|
@@ -515,11 +422,11 @@ async function ignite(config) {
|
|
|
515
422
|
origin = true;
|
|
516
423
|
}
|
|
517
424
|
const corsOpts = typeof corsOption === "object" ? { ...corsOption, origin } : { origin };
|
|
518
|
-
app.use((0,
|
|
425
|
+
app.use(_cors2.default.call(void 0, corsOpts));
|
|
519
426
|
}
|
|
520
|
-
app.use(
|
|
521
|
-
app.use(
|
|
522
|
-
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, ));
|
|
523
430
|
for (const mw of globalMiddlewares) {
|
|
524
431
|
app.use(mw);
|
|
525
432
|
}
|
|
@@ -529,10 +436,10 @@ async function ignite(config) {
|
|
|
529
436
|
}
|
|
530
437
|
if (jwtSecret) {
|
|
531
438
|
const cookieDomain = process.env["COOKIE_DOMAIN"];
|
|
532
|
-
configureAuth({
|
|
439
|
+
_chunkPFJWEU4Ecjs.configureAuth.call(void 0, {
|
|
533
440
|
secret: jwtSecret,
|
|
534
441
|
strategy: authStrategy,
|
|
535
|
-
expiresIn: process.env["JWT_EXPIRES_IN"]
|
|
442
|
+
expiresIn: _nullishCoalesce(process.env["JWT_EXPIRES_IN"], () => ( "7d")),
|
|
536
443
|
...cookieDomain !== void 0 && { cookieDomain }
|
|
537
444
|
});
|
|
538
445
|
}
|
|
@@ -542,12 +449,12 @@ async function ignite(config) {
|
|
|
542
449
|
if (config.tasks) {
|
|
543
450
|
if (config.tasks.backend === "bullmq") {
|
|
544
451
|
await initBullMQ({
|
|
545
|
-
redisUrl: config.tasks.redisUrl
|
|
546
|
-
concurrency: config.tasks.concurrency
|
|
452
|
+
redisUrl: _nullishCoalesce(config.tasks.redisUrl, () => ( "redis://localhost:6379")),
|
|
453
|
+
concurrency: _nullishCoalesce(config.tasks.concurrency, () => ( 5))
|
|
547
454
|
});
|
|
548
455
|
}
|
|
549
456
|
}
|
|
550
|
-
const routes = scanDir(apiDir);
|
|
457
|
+
const routes = _chunkMQNVNOH5cjs.scanDir.call(void 0, apiDir);
|
|
551
458
|
await mountRoutes(app, routes);
|
|
552
459
|
if (onError) {
|
|
553
460
|
app.use(onError);
|
|
@@ -567,9 +474,9 @@ async function ignite(config) {
|
|
|
567
474
|
return new Promise((resolve, reject) => {
|
|
568
475
|
const server = app.listen(port);
|
|
569
476
|
server.once("listening", () => {
|
|
570
|
-
const wid =
|
|
477
|
+
const wid = _nullishCoalesce(_optionalChain([_cluster2.default, 'access', _10 => _10.worker, 'optionalAccess', _11 => _11.id]), () => ( "primary"));
|
|
571
478
|
const addr = server.address();
|
|
572
|
-
console.log(`[EFC] Worker ${wid} listening on :${addr
|
|
479
|
+
console.log(`[EFC] Worker ${wid} listening on :${_nullishCoalesce(_optionalChain([addr, 'optionalAccess', _12 => _12.port]), () => ( port))}`);
|
|
573
480
|
resolve(server);
|
|
574
481
|
});
|
|
575
482
|
server.once("error", reject);
|
|
@@ -595,16 +502,15 @@ function gracefulShutdown(server, timeoutMs = 1e4) {
|
|
|
595
502
|
process.once("SIGTERM", () => shutdown("SIGTERM"));
|
|
596
503
|
process.once("SIGINT", () => shutdown("SIGINT"));
|
|
597
504
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
});
|
|
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;
|
|
610
516
|
//# sourceMappingURL=index.cjs.map
|