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