@universal-middleware/express 0.4.9 → 0.4.10
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.d.ts +1 -1
- package/dist/index.js +25 -7
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ interface DecoratedRequest<C extends Universal.Context = Universal.Context> exte
|
|
|
52
52
|
[requestSymbol]?: Request;
|
|
53
53
|
}
|
|
54
54
|
interface DecoratedServerResponse extends ServerResponse {
|
|
55
|
-
[pendingMiddlewaresSymbol]?: ((response: Response) => Awaitable<Response>)[];
|
|
55
|
+
[pendingMiddlewaresSymbol]?: ((response: Response) => Awaitable<Response | undefined>)[];
|
|
56
56
|
[wrappedResponseSymbol]?: boolean;
|
|
57
57
|
}
|
|
58
58
|
/** Connect/Express style request listener/middleware */
|
package/dist/index.js
CHANGED
|
@@ -197,7 +197,7 @@ function responseAdapter(nodeResponse, bodyInit) {
|
|
|
197
197
|
headers: nodeHeadersToWeb(nodeResponse.getHeaders())
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
|
-
function wrapResponse(nodeResponse) {
|
|
200
|
+
function wrapResponse(nodeResponse, next) {
|
|
201
201
|
if (nodeResponse[wrappedResponseSymbol]) return;
|
|
202
202
|
nodeResponse[wrappedResponseSymbol] = true;
|
|
203
203
|
const body = createTransformStream();
|
|
@@ -214,10 +214,26 @@ function wrapResponse(nodeResponse) {
|
|
|
214
214
|
}
|
|
215
215
|
const middlewares = nodeResponse[pendingMiddlewaresSymbol];
|
|
216
216
|
delete nodeResponse[pendingMiddlewaresSymbol];
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
let response = void 0;
|
|
218
|
+
try {
|
|
219
|
+
response = responseAdapter(nodeResponse, reader1);
|
|
220
|
+
for (const middleware of middlewares) {
|
|
221
|
+
const tmp = await middleware(response);
|
|
222
|
+
if (tmp) response = tmp;
|
|
223
|
+
}
|
|
224
|
+
} catch (e) {
|
|
225
|
+
response = void 0;
|
|
226
|
+
await writer.abort();
|
|
227
|
+
original.writeHead.restore();
|
|
228
|
+
original.write.restore();
|
|
229
|
+
original.end.restore();
|
|
230
|
+
if (next) {
|
|
231
|
+
next(e);
|
|
232
|
+
} else {
|
|
233
|
+
throw e;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!response) return;
|
|
221
237
|
const readableToOriginal = response.body ?? reader2;
|
|
222
238
|
setHeaders(response, nodeResponse, true);
|
|
223
239
|
original.writeHead.restore();
|
|
@@ -326,7 +342,8 @@ function createMiddleware(middlewareFactory, options = {}) {
|
|
|
326
342
|
"Universal Middleware called after headers have been sent. Please open an issue at https://github.com/magne4000/universal-middleware"
|
|
327
343
|
);
|
|
328
344
|
}
|
|
329
|
-
|
|
345
|
+
if (req.complete === void 0) req.complete = req._readableState?.ended ?? true;
|
|
346
|
+
wrapResponse(res, next);
|
|
330
347
|
res[pendingMiddlewaresSymbol] ??= [];
|
|
331
348
|
res[pendingMiddlewaresSymbol].push(response);
|
|
332
349
|
return nextOr404(res, next);
|
|
@@ -518,7 +535,8 @@ var UniversalExpressRouter = class extends UniversalRouter {
|
|
|
518
535
|
};
|
|
519
536
|
function apply(app, middlewares) {
|
|
520
537
|
const router = new UniversalExpressRouter(app);
|
|
521
|
-
applyCore(router, middlewares);
|
|
538
|
+
applyCore(router, middlewares, true);
|
|
539
|
+
Promise.resolve().then(() => router.applyCatchAll());
|
|
522
540
|
}
|
|
523
541
|
export {
|
|
524
542
|
apply,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-middleware/express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express adapter for universal middlewares",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
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.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@swc/core": "^1.11.13",
|