kaelum 1.8.0 → 1.8.1

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.
@@ -94,17 +94,13 @@ function errorHandlerFactory(options = {}) {
94
94
  }
95
95
 
96
96
  // onError hook (e.g., report to external service)
97
- try {
98
- if (typeof onError === "function") {
99
- try {
100
- onError(normalizedErr, req, res);
101
- } catch (hookErr) {
102
- // don't block response if hook fails
103
- console.error("Kaelum errorHandler: onError hook threw", hookErr);
104
- }
97
+ if (typeof onError === "function") {
98
+ try {
99
+ onError(normalizedErr, req, res);
100
+ } catch (hookErr) {
101
+ // don't block response if hook fails
102
+ console.error("Kaelum errorHandler: onError hook threw", hookErr);
105
103
  }
106
- } catch (_) {
107
- // ignore
108
104
  }
109
105
 
110
106
  // Respond according to Accept header: JSON preferred, fallback to text/html
package/core/setConfig.js CHANGED
@@ -28,7 +28,6 @@ function persistConfig(app, options = {}) {
28
28
  return merged;
29
29
  }
30
30
 
31
- // removeMiddlewareByFn imported from ./utils.js
32
31
 
33
32
  /**
34
33
  * Remove static middleware previously installed by Kaelum (if any)
@@ -175,8 +174,8 @@ function setConfig(app, options = {}) {
175
174
  removeKaelumStatic(app);
176
175
 
177
176
  if (options.static) {
178
- const expressStatic =
179
- tryRequire("express").static || require("express").static;
177
+ const expressModule = require("express");
178
+ const expressStatic = expressModule.static;
180
179
  // resolve to absolute path relative to project root if necessary
181
180
  const dir =
182
181
  typeof options.static === "string"
@@ -204,8 +203,9 @@ function setConfig(app, options = {}) {
204
203
  !app.locals._kaelum_bodyparsers ||
205
204
  app.locals._kaelum_bodyparsers.length === 0
206
205
  ) {
207
- const jsonParser = tryRequire("express").json();
208
- const urlencodedParser = tryRequire("express").urlencoded({
206
+ const expressModule = require("express");
207
+ const jsonParser = expressModule.json();
208
+ const urlencodedParser = expressModule.urlencoded({
209
209
  extended: true,
210
210
  });
211
211
  app.locals._kaelum_bodyparsers = [jsonParser, urlencodedParser];
package/core/start.js CHANGED
@@ -46,24 +46,14 @@ function start(app, port, cb) {
46
46
  app.get && app.get("kaelum:config")
47
47
  ? app.get("kaelum:config")
48
48
  : app.locals && app.locals.kaelumConfig
49
- ? app.locals.kaelumConfig
50
- : {};
49
+ ? app.locals.kaelumConfig
50
+ : {};
51
51
 
52
52
  // determine port precedence: explicit argument -> config -> default
53
- let usePort;
54
- try {
55
- usePort = normalizePort(port);
56
- } catch (err) {
57
- throw err;
58
- }
53
+ let usePort = normalizePort(port);
59
54
 
60
55
  if (typeof usePort === "undefined") {
61
- try {
62
- usePort = normalizePort(cfg && cfg.port);
63
- } catch (err) {
64
- // config had invalid port — surface error
65
- throw err;
66
- }
56
+ usePort = normalizePort(cfg && cfg.port);
67
57
  }
68
58
 
69
59
  if (typeof usePort === "undefined") {
package/createApp.js CHANGED
@@ -70,6 +70,7 @@ function createApp() {
70
70
  }
71
71
  } catch (e) {
72
72
  // fallback merge and persist locally
73
+ console.warn("Kaelum setConfig: core module error, falling back to manual merge.", e.message || e);
73
74
  const prev = app.locals.kaelumConfig || {};
74
75
  app.locals.kaelumConfig = Object.assign({}, prev, options);
75
76
  app.set("kaelum:config", app.locals.kaelumConfig);
@@ -110,24 +111,28 @@ function createApp() {
110
111
  // ---------------------------
111
112
  // bind existing core helpers to the app
112
113
  // ---------------------------
114
+ /** Start the HTTP server on the given port. @param {number|string} port @param {Function} [cb] @returns {import('http').Server} */
113
115
  if (typeof start === "function") {
114
116
  app.start = function (port, cb) {
115
117
  return start(app, port, cb);
116
118
  };
117
119
  }
118
120
 
121
+ /** Register routes with flexible handler objects. @param {string} routePath @param {Object|Function|Array} handlers */
119
122
  if (typeof addRoute === "function") {
120
123
  app.addRoute = function (routePath, handlers) {
121
124
  return addRoute(app, routePath, handlers);
122
125
  };
123
126
  }
124
127
 
128
+ /** Register RESTful API routes for a resource. @param {string} resource @param {Object} handlers */
125
129
  if (typeof apiRoute === "function") {
126
130
  app.apiRoute = function (resource, handlers) {
127
131
  return apiRoute(app, resource, handlers);
128
132
  };
129
133
  }
130
134
 
135
+ /** Register middleware, optionally scoped to a path. @param {string|Function|Array} middlewareOrPath @param {Function|Array} [maybeMiddleware] */
131
136
  if (typeof setMiddleware === "function") {
132
137
  app.setMiddleware = function (middlewareOrPath, maybeMiddleware) {
133
138
  // forward call to core/setMiddleware - keep signature flexible
@@ -138,6 +143,7 @@ function createApp() {
138
143
  };
139
144
  }
140
145
 
146
+ /** Register a health check endpoint. @param {string|HealthOptions} routePath @returns {KaelumApp} */
141
147
  if (typeof registerHealth === "function") {
142
148
  app.healthCheck = function (routePath = "/health") {
143
149
  registerHealth(app, routePath);
@@ -145,6 +151,7 @@ function createApp() {
145
151
  };
146
152
  }
147
153
 
154
+ /** Register redirect route(s). @param {string|Object|Array} from @param {string} [to] @param {number} [status=302] */
148
155
  if (typeof redirect === "function") {
149
156
  app.redirect = function (from, to, status = 302) {
150
157
  return redirect(app, from, to, status);
@@ -177,10 +184,12 @@ function createApp() {
177
184
  // ---------------------------
178
185
  // Plugin system
179
186
  // ---------------------------
187
+ /** Register a plugin function. @param {Function} fn @param {Object} [options] @returns {KaelumApp} */
180
188
  app.plugin = function (fn, options) {
181
189
  return registerPlugin(app, fn, options);
182
190
  };
183
191
 
192
+ /** List registered plugin names. @returns {string[]} */
184
193
  app.getPlugins = function () {
185
194
  return getPlugins(app);
186
195
  };
@@ -188,10 +197,12 @@ function createApp() {
188
197
  // ---------------------------
189
198
  // Graceful shutdown
190
199
  // ---------------------------
200
+ /** Register a cleanup function to run during graceful shutdown. @param {Function} fn @returns {KaelumApp} */
191
201
  app.onShutdown = function (fn) {
192
202
  return onShutdown(app, fn);
193
203
  };
194
204
 
205
+ /** Gracefully close the server and run cleanup hooks. @param {Function} [cb] @returns {Promise<void>|KaelumApp} */
195
206
  app.close = function (cb) {
196
207
  return close(app, cb);
197
208
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kaelum",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "A minimalist Node.js framework for building web pages and APIs with simplicity and speed.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",