@universal-middleware/express 0.4.1 → 0.4.3
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/index.js +12 -4
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -258,6 +258,14 @@ var pendingMiddlewaresSymbol = Symbol.for("unPendingMiddlewares");
|
|
|
258
258
|
var wrappedResponseSymbol = Symbol.for("unWrappedResponse");
|
|
259
259
|
var pendingWritesSymbol = Symbol.for("unPendingWrites");
|
|
260
260
|
var env = typeof globalThis.process?.env !== "undefined" ? globalThis.process.env : typeof import.meta?.env !== "undefined" ? import.meta.env : {};
|
|
261
|
+
function nextOr404(res, next) {
|
|
262
|
+
if (next) {
|
|
263
|
+
next();
|
|
264
|
+
} else {
|
|
265
|
+
res.statusCode = 404;
|
|
266
|
+
res.end();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
261
269
|
function createHandler(handlerFactory, options = {}) {
|
|
262
270
|
const requestAdapter = createRequestAdapter(options);
|
|
263
271
|
return (...args) => {
|
|
@@ -272,7 +280,7 @@ function createHandler(handlerFactory, options = {}) {
|
|
|
272
280
|
getRuntime(req, res)
|
|
273
281
|
);
|
|
274
282
|
if (!response) {
|
|
275
|
-
next
|
|
283
|
+
nextOr404(res, next);
|
|
276
284
|
} else {
|
|
277
285
|
await sendResponse(response, res);
|
|
278
286
|
}
|
|
@@ -302,7 +310,7 @@ function createMiddleware(middlewareFactory, options = {}) {
|
|
|
302
310
|
const request = requestAdapter(req);
|
|
303
311
|
const response = await this[universalSymbol](request, getContext(req), getRuntime(req, res));
|
|
304
312
|
if (!response) {
|
|
305
|
-
return next
|
|
313
|
+
return nextOr404(res, next);
|
|
306
314
|
}
|
|
307
315
|
if (typeof response === "function") {
|
|
308
316
|
if (res.headersSent) {
|
|
@@ -313,13 +321,13 @@ function createMiddleware(middlewareFactory, options = {}) {
|
|
|
313
321
|
wrapResponse(res);
|
|
314
322
|
res[pendingMiddlewaresSymbol] ??= [];
|
|
315
323
|
res[pendingMiddlewaresSymbol].push(response);
|
|
316
|
-
return next
|
|
324
|
+
return nextOr404(res, next);
|
|
317
325
|
}
|
|
318
326
|
if (response instanceof Response) {
|
|
319
327
|
await sendResponse(response, res);
|
|
320
328
|
} else {
|
|
321
329
|
req[contextSymbol] = response;
|
|
322
|
-
return next
|
|
330
|
+
return nextOr404(res, next);
|
|
323
331
|
}
|
|
324
332
|
} catch (error) {
|
|
325
333
|
if (next) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-middleware/express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express adapter for universal middlewares",
|
|
6
6
|
"files": [
|
|
@@ -13,20 +13,20 @@
|
|
|
13
13
|
"repository": "https://github.com/magne4000/universal-middleware",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@universal-middleware/core": "^0.4.
|
|
16
|
+
"@universal-middleware/core": "^0.4.1"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@swc/core": "^1.10.
|
|
19
|
+
"@swc/core": "^1.10.18",
|
|
20
20
|
"@types/express": "^4.17.21",
|
|
21
|
-
"@types/node": "^20.17.
|
|
21
|
+
"@types/node": "^20.17.19",
|
|
22
22
|
"express": "^4.21.2",
|
|
23
23
|
"helmet": "^8.0.0",
|
|
24
24
|
"rimraf": "^6.0.1",
|
|
25
25
|
"tsup": "^8.3.6",
|
|
26
|
-
"tsx": "^4.19.
|
|
26
|
+
"tsx": "^4.19.3",
|
|
27
27
|
"typescript": "^5.7.3",
|
|
28
|
-
"vite": "^6.1.
|
|
29
|
-
"vitest": "^3.0.
|
|
28
|
+
"vite": "^6.1.1",
|
|
29
|
+
"vitest": "^3.0.6",
|
|
30
30
|
"@universal-middleware/tests": "0.0.0"
|
|
31
31
|
},
|
|
32
32
|
"sideEffects": false,
|