express-file-cluster 0.10.0 → 0.10.2

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.
Files changed (186) hide show
  1. package/dist/auth/index.cjs +7 -6
  2. package/dist/auth/index.cjs.map +1 -1
  3. package/dist/auth/index.d.cts +1 -1
  4. package/dist/auth/index.d.ts +1 -1
  5. package/dist/auth/index.js +5 -5
  6. package/dist/{chunk-R52CUEGT.js → chunk-3SWI46YK.js} +2 -2
  7. package/dist/{chunk-DCJOWFVD.cjs → chunk-4GHK27JA.cjs} +3 -3
  8. package/dist/{chunk-DCJOWFVD.cjs.map → chunk-4GHK27JA.cjs.map} +1 -1
  9. package/dist/{chunk-NI2BNGGV.js → chunk-5LPRKZPB.js} +2 -2
  10. package/dist/chunk-74BSJXWD.cjs +220 -0
  11. package/dist/chunk-74BSJXWD.cjs.map +1 -0
  12. package/dist/{chunk-7KO4DJRJ.cjs → chunk-7BC3AN7R.cjs} +14 -14
  13. package/dist/{chunk-7KO4DJRJ.cjs.map → chunk-7BC3AN7R.cjs.map} +1 -1
  14. package/dist/chunk-AGOYTFRO.cjs +42 -0
  15. package/dist/chunk-AGOYTFRO.cjs.map +1 -0
  16. package/dist/{chunk-RAB44UGX.js → chunk-B6MB6HEG.js} +1 -1
  17. package/dist/{chunk-PGJQK36V.js → chunk-BG4A7Z32.js} +7 -5
  18. package/dist/{chunk-PGJQK36V.js.map → chunk-BG4A7Z32.js.map} +1 -1
  19. package/dist/{chunk-ATVD2HGC.js → chunk-C2FOZ7ME.js} +4 -4
  20. package/dist/chunk-CGY7JU4Y.cjs +8 -0
  21. package/dist/chunk-CGY7JU4Y.cjs.map +1 -0
  22. package/dist/{chunk-EGSSZUVO.js → chunk-DN4TCGYB.js} +38 -11
  23. package/dist/chunk-DN4TCGYB.js.map +1 -0
  24. package/dist/{chunk-GBI77W5T.cjs → chunk-H2PVWCWC.cjs} +1 -1
  25. package/dist/{chunk-GBI77W5T.cjs.map → chunk-H2PVWCWC.cjs.map} +1 -1
  26. package/dist/{chunk-NKLOE4AK.cjs → chunk-IUZ6A7PB.cjs} +20 -53
  27. package/dist/chunk-IUZ6A7PB.cjs.map +1 -0
  28. package/dist/{chunk-DUADUR6R.cjs → chunk-JP36TLL4.cjs} +171 -14
  29. package/dist/chunk-JP36TLL4.cjs.map +1 -0
  30. package/dist/chunk-KLWL7XSC.js +220 -0
  31. package/dist/chunk-KLWL7XSC.js.map +1 -0
  32. package/dist/{chunk-4DOHQU6I.cjs → chunk-M53GODCX.cjs} +39 -12
  33. package/dist/chunk-M53GODCX.cjs.map +1 -0
  34. package/dist/{chunk-R4XO4SVM.js → chunk-MUVO7MGS.js} +4 -4
  35. package/dist/{chunk-HBCY7ILD.cjs → chunk-R2K7AFIB.cjs} +97 -95
  36. package/dist/chunk-R2K7AFIB.cjs.map +1 -0
  37. package/dist/{chunk-QDEDOHP7.js → chunk-RETV3GKE.js} +9 -42
  38. package/dist/chunk-RETV3GKE.js.map +1 -0
  39. package/dist/{chunk-WBLUGOAG.cjs → chunk-RPL2IFWK.cjs} +8 -5
  40. package/dist/chunk-RPL2IFWK.cjs.map +1 -0
  41. package/dist/{chunk-YK4ZM3CA.cjs → chunk-TBIVIR6L.cjs} +15 -15
  42. package/dist/{chunk-YK4ZM3CA.cjs.map → chunk-TBIVIR6L.cjs.map} +1 -1
  43. package/dist/{chunk-73XJUT2S.js → chunk-V73R76I4.js} +162 -5
  44. package/dist/chunk-V73R76I4.js.map +1 -0
  45. package/dist/chunk-XPY5TQDK.js +42 -0
  46. package/dist/chunk-XPY5TQDK.js.map +1 -0
  47. package/dist/{chunk-KFVFP2Q7.cjs → chunk-Y4NKIXUL.cjs} +70 -55
  48. package/dist/chunk-Y4NKIXUL.cjs.map +1 -0
  49. package/dist/{chunk-7KC2H76D.js → chunk-Y75V5FCU.js} +62 -47
  50. package/dist/chunk-Y75V5FCU.js.map +1 -0
  51. package/dist/cli/db-runner.cjs +81 -42
  52. package/dist/cli/db-runner.cjs.map +1 -1
  53. package/dist/cli/db-runner.js +54 -16
  54. package/dist/cli/db-runner.js.map +1 -1
  55. package/dist/cli/index.cjs +23 -25
  56. package/dist/cli/index.cjs.map +1 -1
  57. package/dist/cli/index.js +12 -17
  58. package/dist/cli/index.js.map +1 -1
  59. package/dist/docs/api-reference/auth.md +23 -0
  60. package/dist/docs/api-reference/compose.md +1 -1
  61. package/dist/docs/api-reference/db.md +8 -0
  62. package/dist/docs/api-reference/ignite.md +4 -1
  63. package/dist/docs/api-reference/testing.md +26 -0
  64. package/dist/docs/cli/add.md +2 -2
  65. package/dist/docs/core-concepts/file-based-routing.md +2 -0
  66. package/dist/docs/core-concepts/middleware.md +2 -2
  67. package/dist/docs/getting-started/index.md +4 -0
  68. package/dist/docs/guides/authentication.md +33 -0
  69. package/dist/docs/guides/caching.md +2 -0
  70. package/dist/docs/guides/database.md +15 -0
  71. package/dist/docs/guides/environment-variables.md +6 -0
  72. package/dist/docs/guides/generated-portals.md +3 -1
  73. package/dist/docs/guides/logging.md +17 -0
  74. package/dist/docs/guides/migrations.md +4 -2
  75. package/dist/docs/guides/testing.md +31 -0
  76. package/dist/docs/index.md +2 -1
  77. package/dist/docs/skills/SKILL.md +5 -1
  78. package/dist/docs/skills/api-surface.md +20 -4
  79. package/dist/docs/skills/auth-internals.md +14 -1
  80. package/dist/docs/skills/pre-flight.md +6 -0
  81. package/dist/docs/skills/routing-rules.md +1 -1
  82. package/dist/docs/skills/what-not-to-invent.md +9 -1
  83. package/dist/docs/versioning.md +1 -1
  84. package/dist/index.cjs +75 -264
  85. package/dist/index.cjs.map +1 -1
  86. package/dist/index.d.cts +27 -3
  87. package/dist/index.d.ts +27 -3
  88. package/dist/index.js +28 -218
  89. package/dist/index.js.map +1 -1
  90. package/dist/pgboss-backend-4X2YT4RB.js +14 -0
  91. package/dist/pgboss-backend-UXQ3O2WT.cjs +15 -0
  92. package/dist/pgboss-backend-UXQ3O2WT.cjs.map +1 -0
  93. package/dist/registry/index.json +27 -3
  94. package/dist/registry/js-mongo/account-security.json +1 -1
  95. package/dist/registry/js-mongo/admin-users.json +1 -1
  96. package/dist/registry/js-mongo/auth.json +1 -1
  97. package/dist/registry/js-mongo/auth@apple.json +1 -1
  98. package/dist/registry/js-mongo/auth@google.json +1 -1
  99. package/dist/registry/js-mongo/forgot-password.json +1 -1
  100. package/dist/registry/js-mongo/user-profile.json +1 -1
  101. package/dist/registry/js-mongo-collection/account-security.json +1 -1
  102. package/dist/registry/js-mongo-collection/admin-users.json +1 -1
  103. package/dist/registry/js-mongo-collection/auth.json +1 -1
  104. package/dist/registry/js-mongo-collection/auth@apple.json +1 -1
  105. package/dist/registry/js-mongo-collection/auth@google.json +1 -1
  106. package/dist/registry/js-mongo-collection/forgot-password.json +1 -1
  107. package/dist/registry/js-mongo-collection/user-profile.json +1 -1
  108. package/dist/registry/js-pg-model/account-security.json +1 -1
  109. package/dist/registry/js-pg-model/admin-users.json +1 -1
  110. package/dist/registry/js-pg-model/auth.json +1 -1
  111. package/dist/registry/js-pg-model/auth@apple.json +1 -1
  112. package/dist/registry/js-pg-model/auth@google.json +1 -1
  113. package/dist/registry/js-pg-model/forgot-password.json +1 -1
  114. package/dist/registry/js-pg-model/user-profile.json +1 -1
  115. package/dist/registry/js-pg-table/account-security.json +1 -1
  116. package/dist/registry/js-pg-table/admin-users.json +1 -1
  117. package/dist/registry/js-pg-table/auth.json +1 -1
  118. package/dist/registry/js-pg-table/auth@apple.json +1 -1
  119. package/dist/registry/js-pg-table/auth@google.json +1 -1
  120. package/dist/registry/js-pg-table/forgot-password.json +1 -1
  121. package/dist/registry/js-pg-table/user-profile.json +1 -1
  122. package/dist/registry/ts-mongo/account-security.json +1 -1
  123. package/dist/registry/ts-mongo/admin-users.json +1 -1
  124. package/dist/registry/ts-mongo/auth.json +1 -1
  125. package/dist/registry/ts-mongo/auth@apple.json +1 -1
  126. package/dist/registry/ts-mongo/auth@google.json +1 -1
  127. package/dist/registry/ts-mongo/forgot-password.json +1 -1
  128. package/dist/registry/ts-mongo/user-profile.json +1 -1
  129. package/dist/registry/ts-mongo-collection/account-security.json +1 -1
  130. package/dist/registry/ts-mongo-collection/admin-users.json +1 -1
  131. package/dist/registry/ts-mongo-collection/auth.json +1 -1
  132. package/dist/registry/ts-mongo-collection/auth@apple.json +1 -1
  133. package/dist/registry/ts-mongo-collection/auth@google.json +1 -1
  134. package/dist/registry/ts-mongo-collection/forgot-password.json +1 -1
  135. package/dist/registry/ts-mongo-collection/user-profile.json +1 -1
  136. package/dist/registry/ts-pg-model/account-security.json +1 -1
  137. package/dist/registry/ts-pg-model/admin-users.json +1 -1
  138. package/dist/registry/ts-pg-model/auth.json +1 -1
  139. package/dist/registry/ts-pg-model/auth@apple.json +1 -1
  140. package/dist/registry/ts-pg-model/auth@google.json +1 -1
  141. package/dist/registry/ts-pg-model/forgot-password.json +1 -1
  142. package/dist/registry/ts-pg-model/user-profile.json +1 -1
  143. package/dist/registry/ts-pg-table/account-security.json +1 -1
  144. package/dist/registry/ts-pg-table/admin-users.json +1 -1
  145. package/dist/registry/ts-pg-table/auth.json +1 -1
  146. package/dist/registry/ts-pg-table/auth@apple.json +1 -1
  147. package/dist/registry/ts-pg-table/auth@google.json +1 -1
  148. package/dist/registry/ts-pg-table/forgot-password.json +1 -1
  149. package/dist/registry/ts-pg-table/user-profile.json +1 -1
  150. package/dist/tasks/index.cjs +3 -2
  151. package/dist/tasks/index.cjs.map +1 -1
  152. package/dist/tasks/index.d.cts +1 -1
  153. package/dist/tasks/index.d.ts +1 -1
  154. package/dist/tasks/index.js +1 -1
  155. package/dist/testing-cjs.cjs +5 -0
  156. package/dist/testing.cjs +59 -0
  157. package/dist/testing.cjs.map +1 -0
  158. package/dist/testing.d.cts +27 -0
  159. package/dist/testing.d.ts +27 -0
  160. package/dist/testing.js +58 -0
  161. package/dist/testing.js.map +1 -0
  162. package/dist/thread-runner.cjs +4 -3
  163. package/dist/thread-runner.cjs.map +1 -1
  164. package/dist/thread-runner.js +2 -2
  165. package/dist/{types-Bnxvj3l0.d.ts → types-CPMFTVXm.d.cts} +8 -0
  166. package/dist/{types-Bnxvj3l0.d.cts → types-CPMFTVXm.d.ts} +8 -0
  167. package/package.json +6 -1
  168. package/dist/chunk-4DOHQU6I.cjs.map +0 -1
  169. package/dist/chunk-73XJUT2S.js.map +0 -1
  170. package/dist/chunk-7KC2H76D.js.map +0 -1
  171. package/dist/chunk-DUADUR6R.cjs.map +0 -1
  172. package/dist/chunk-EGSSZUVO.js.map +0 -1
  173. package/dist/chunk-HBCY7ILD.cjs.map +0 -1
  174. package/dist/chunk-KFVFP2Q7.cjs.map +0 -1
  175. package/dist/chunk-NKLOE4AK.cjs.map +0 -1
  176. package/dist/chunk-QDEDOHP7.js.map +0 -1
  177. package/dist/chunk-WBLUGOAG.cjs.map +0 -1
  178. package/dist/pgboss-backend-FW42SBSM.js +0 -14
  179. package/dist/pgboss-backend-RVHUBJTU.cjs +0 -14
  180. package/dist/pgboss-backend-RVHUBJTU.cjs.map +0 -1
  181. /package/dist/{chunk-R52CUEGT.js.map → chunk-3SWI46YK.js.map} +0 -0
  182. /package/dist/{chunk-NI2BNGGV.js.map → chunk-5LPRKZPB.js.map} +0 -0
  183. /package/dist/{chunk-RAB44UGX.js.map → chunk-B6MB6HEG.js.map} +0 -0
  184. /package/dist/{chunk-ATVD2HGC.js.map → chunk-C2FOZ7ME.js.map} +0 -0
  185. /package/dist/{chunk-R4XO4SVM.js.map → chunk-MUVO7MGS.js.map} +0 -0
  186. /package/dist/{pgboss-backend-FW42SBSM.js.map → pgboss-backend-4X2YT4RB.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ createHttpApp,
3
+ mountErrorHandler,
4
+ mountRoutes
5
+ } from "./chunk-KLWL7XSC.js";
1
6
  import {
2
7
  cache,
3
8
  closeCache,
@@ -6,14 +11,14 @@ import {
6
11
  isCacheConfigured,
7
12
  rawIncr,
8
13
  servePrimaryCache
9
- } from "./chunk-7KC2H76D.js";
14
+ } from "./chunk-Y75V5FCU.js";
10
15
  import {
11
16
  scanDir
12
- } from "./chunk-NI2BNGGV.js";
17
+ } from "./chunk-5LPRKZPB.js";
13
18
  import {
14
19
  closeBullMQ,
15
20
  initBullMQ
16
- } from "./chunk-ATVD2HGC.js";
21
+ } from "./chunk-C2FOZ7ME.js";
17
22
  import {
18
23
  connectMongo,
19
24
  db,
@@ -23,23 +28,25 @@ import {
23
28
  getDbClient,
24
29
  setDbClient,
25
30
  transaction
26
- } from "./chunk-PGJQK36V.js";
31
+ } from "./chunk-BG4A7Z32.js";
27
32
  import {
28
- HttpError,
29
33
  ModelValidationError,
30
- isHttpError,
31
34
  setAutoSync,
32
35
  setDbEngine
33
- } from "./chunk-QDEDOHP7.js";
36
+ } from "./chunk-RETV3GKE.js";
37
+ import {
38
+ HttpError,
39
+ isHttpError
40
+ } from "./chunk-XPY5TQDK.js";
34
41
  import {
35
42
  closePgBoss,
36
43
  initPgBoss
37
- } from "./chunk-R4XO4SVM.js";
38
- import "./chunk-R52CUEGT.js";
44
+ } from "./chunk-MUVO7MGS.js";
45
+ import "./chunk-3SWI46YK.js";
39
46
  import {
40
47
  listTasks,
41
48
  registerTask
42
- } from "./chunk-RAB44UGX.js";
49
+ } from "./chunk-B6MB6HEG.js";
43
50
  import {
44
51
  checkConnectionBudget,
45
52
  configureLogger,
@@ -47,153 +54,18 @@ import {
47
54
  connectPostgres,
48
55
  getCurrentUser,
49
56
  getLogger,
57
+ getQueryMetrics,
50
58
  logger,
51
- requestLogger,
52
- runWithContext
53
- } from "./chunk-73XJUT2S.js";
59
+ resetQueryMetrics
60
+ } from "./chunk-V73R76I4.js";
54
61
 
55
62
  // src/index.ts
56
63
  import fs2 from "fs";
57
64
  import express from "express";
58
- import cors from "cors";
59
- import cookieParser from "cookie-parser";
60
65
  import cluster2 from "cluster";
61
66
  import os from "os";
62
67
  import path2 from "path";
63
68
 
64
- // src/router/validate.ts
65
- var LOCATIONS = ["params", "query", "body"];
66
- function isRequestSchema(value) {
67
- return value != null && typeof value === "object" && LOCATIONS.some((loc) => loc in value);
68
- }
69
- function schemaFor(schema, method) {
70
- if (!schema) return void 0;
71
- const byMethod = schema[method];
72
- if (isRequestSchema(byMethod)) return byMethod;
73
- return isRequestSchema(schema) ? schema : void 0;
74
- }
75
- function pathToString(path3) {
76
- if (!path3) return "";
77
- return path3.map((p) => typeof p === "object" && p !== null && "key" in p ? p.key : p).map(String).join(".");
78
- }
79
- async function run(validator, input) {
80
- const std = validator["~standard"];
81
- if (std && typeof std.validate === "function") {
82
- return await std.validate(input);
83
- }
84
- const v = validator;
85
- const parse = v.safeParseAsync ?? v.safeParse;
86
- if (typeof parse !== "function") {
87
- throw new Error("[EFC] Route schema entries must be Standard Schema validators (e.g. zod)");
88
- }
89
- const r = await parse.call(validator, input);
90
- return r.success ? { value: r.data } : { issues: r.error?.issues ?? [{ message: "Invalid" }] };
91
- }
92
- function validateRequest(schema) {
93
- return (req, res, next) => {
94
- void (async () => {
95
- const issues = [];
96
- const parsed = {};
97
- for (const location of LOCATIONS) {
98
- const validator = schema[location];
99
- if (!validator) continue;
100
- const result = await run(validator, req[location]);
101
- if (result.issues) {
102
- for (const issue of result.issues) {
103
- issues.push({ location, path: pathToString(issue.path), message: issue.message });
104
- }
105
- } else {
106
- parsed[location] = result.value;
107
- }
108
- }
109
- if (issues.length > 0) {
110
- res.status(400).json({ error: "Validation failed", statusCode: 400, issues });
111
- return;
112
- }
113
- for (const location of LOCATIONS) {
114
- if (location in parsed) {
115
- Object.defineProperty(req, location, {
116
- value: parsed[location],
117
- writable: true,
118
- configurable: true,
119
- enumerable: true
120
- });
121
- }
122
- }
123
- next();
124
- })().catch(next);
125
- };
126
- }
127
-
128
- // src/router/mount.ts
129
- var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
130
- function asyncWrap(handler) {
131
- return (req, res, next) => {
132
- Promise.resolve(handler(req, res, next)).catch(next);
133
- };
134
- }
135
- function namedParams(route) {
136
- const catchAlls = new Set([...route.urlPath.matchAll(/:([A-Za-z0-9_$]+)\*/g)].map((m) => m[1]));
137
- return (req, _res, next) => {
138
- const positional = req.params;
139
- const named = {};
140
- route.params.forEach((name, i) => {
141
- const value = positional[String(i)];
142
- if (value === void 0 || value === "") {
143
- named[name] = catchAlls.has(name) ? [] : void 0;
144
- } else if (catchAlls.has(name)) {
145
- named[name] = value.split("/").filter(Boolean).map(decodeURIComponent);
146
- } else {
147
- named[name] = decodeURIComponent(value);
148
- }
149
- });
150
- req.params = named;
151
- next();
152
- };
153
- }
154
- async function mountRoutes(app, routes) {
155
- const mounted = [];
156
- for (const route of routes) {
157
- const mod = await import(route.filePath);
158
- const routeMiddlewares = Array.isArray(mod["middlewares"]) ? mod["middlewares"] : [];
159
- const raw = mod["meta"];
160
- const meta = raw != null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
161
- const schema = mod["schema"] != null && typeof mod["schema"] === "object" ? mod["schema"] : void 0;
162
- const routePath = route.pattern ?? route.urlPath;
163
- const paramMapper = route.pattern ? [namedParams(route)] : [];
164
- const implemented = [];
165
- const unimplemented = [];
166
- for (const method of HTTP_METHODS) {
167
- if (typeof mod[method] === "function") {
168
- implemented.push(method);
169
- const methodSchema = schemaFor(schema, method);
170
- const validation = methodSchema ? [validateRequest(methodSchema)] : [];
171
- app[method.toLowerCase()](
172
- routePath,
173
- ...paramMapper,
174
- ...routeMiddlewares,
175
- ...validation,
176
- asyncWrap(mod[method])
177
- );
178
- } else {
179
- unimplemented.push(method);
180
- }
181
- }
182
- if (implemented.length > 0 && unimplemented.length > 0) {
183
- const allowHeader = implemented.join(", ");
184
- app.all(routePath, (req, res, next) => {
185
- if (unimplemented.includes(req.method)) {
186
- res.set("Allow", allowHeader).status(405).json({ error: "Method Not Allowed" });
187
- } else {
188
- next();
189
- }
190
- });
191
- }
192
- mounted.push({ ...route, methods: implemented, ...meta !== void 0 && { meta } });
193
- }
194
- return mounted;
195
- }
196
-
197
69
  // src/cluster/index.ts
198
70
  import cluster from "cluster";
199
71
  var isShuttingDown = false;
@@ -966,7 +838,9 @@ function compose(...handlers) {
966
838
  return;
967
839
  }
968
840
  try {
969
- Promise.resolve(handler(req, res, () => dispatch(i + 1))).catch(next);
841
+ Promise.resolve(
842
+ handler(req, res, (err) => err ? next(err) : dispatch(i + 1))
843
+ ).catch(next);
970
844
  } catch (err) {
971
845
  next(err);
972
846
  }
@@ -983,14 +857,7 @@ function detectDatabase(url) {
983
857
  return void 0;
984
858
  }
985
859
  async function ignite(config) {
986
- const {
987
- port: _port,
988
- workers,
989
- globalMiddlewares = [],
990
- onWorkerReady,
991
- onWorkerCrash,
992
- onError
993
- } = config;
860
+ const { port: _port, workers, onWorkerReady, onWorkerCrash, onError } = config;
994
861
  function resolveConventionDir(name) {
995
862
  const candidates = [
996
863
  ...process.argv[1] ? [path2.join(path2.dirname(process.argv[1]), name)] : [],
@@ -1041,40 +908,7 @@ async function ignite(config) {
1041
908
  });
1042
909
  return;
1043
910
  }
1044
- const app = express();
1045
- if (config.trustProxy !== void 0) app.set("trust proxy", config.trustProxy);
1046
- app.set(
1047
- "json replacer",
1048
- (_key, value) => typeof value === "bigint" ? value.toString() : value
1049
- );
1050
- app.use((_req, _res, next) => {
1051
- runWithContext({}, next);
1052
- });
1053
- app.use(requestLogger());
1054
- if (config.requestTimeout) {
1055
- const ms = config.requestTimeout;
1056
- app.use((_req, res, next) => {
1057
- const timer = setTimeout(() => {
1058
- if (!res.headersSent) res.status(408).json({ error: "Request Timeout", statusCode: 408 });
1059
- }, ms);
1060
- const clear = () => clearTimeout(timer);
1061
- res.once("finish", clear);
1062
- res.once("close", clear);
1063
- next();
1064
- });
1065
- }
1066
- const corsOption = config.cors ?? true;
1067
- if (corsOption !== false) {
1068
- const origin = typeof corsOption === "object" && corsOption.origin !== void 0 ? corsOption.origin : true;
1069
- const corsOpts = typeof corsOption === "object" ? { ...corsOption, origin } : { origin };
1070
- app.use(cors(corsOpts));
1071
- }
1072
- app.use(express.json());
1073
- app.use(express.urlencoded({ extended: true }));
1074
- app.use(cookieParser());
1075
- for (const mw of globalMiddlewares) {
1076
- app.use(mw);
1077
- }
911
+ const app = createHttpApp(config);
1078
912
  if (database) setDbEngine(database);
1079
913
  setAutoSync(config.autoSync ?? true);
1080
914
  const poolWorkers = clusterEnabled ? workers ?? os.cpus().length : 1;
@@ -1147,33 +981,7 @@ async function ignite(config) {
1147
981
  res.send(generateDashboard(mounted, basePath, port, name, version));
1148
982
  });
1149
983
  }
1150
- if (onError) {
1151
- app.use(onError);
1152
- } else {
1153
- app.use(
1154
- (err, _req, res, _next) => {
1155
- if (res.headersSent) {
1156
- getLogger().warn({ err }, "Error after the response was sent");
1157
- return;
1158
- }
1159
- const status = err?.statusCode;
1160
- const duckTyped = err instanceof Error && typeof status === "number" && status >= 400 && status < 500 ? err : null;
1161
- if (isHttpError(err)) {
1162
- const issues = err.issues;
1163
- res.status(err.statusCode).json({
1164
- error: err.message,
1165
- statusCode: err.statusCode,
1166
- ...issues !== void 0 && { issues }
1167
- });
1168
- } else if (duckTyped) {
1169
- res.status(duckTyped.statusCode).json({ error: duckTyped.message, statusCode: duckTyped.statusCode });
1170
- } else {
1171
- getLogger().error({ err }, "Unhandled error");
1172
- res.status(500).json({ error: "Internal Server Error", statusCode: 500 });
1173
- }
1174
- }
1175
- );
1176
- }
984
+ mountErrorHandler(app, onError);
1177
985
  return new Promise((resolve, reject) => {
1178
986
  const server = app.listen(port);
1179
987
  server.once("listening", () => {
@@ -1224,12 +1032,14 @@ export {
1224
1032
  defineTable,
1225
1033
  getDbClient,
1226
1034
  getLogger,
1035
+ getQueryMetrics,
1227
1036
  gracefulShutdown,
1228
1037
  ignite,
1229
1038
  isHttpError,
1230
1039
  listTasks,
1231
1040
  logger,
1232
1041
  rateLimit,
1042
+ resetQueryMetrics,
1233
1043
  scanDir,
1234
1044
  setDbClient,
1235
1045
  transaction,