@universal-middleware/express 0.4.11 → 0.4.13
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 +5 -3
- package/dist/index.js +21 -6
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { IncomingMessage, ServerResponse, OutgoingHttpHeaders } from 'node:http'
|
|
|
2
2
|
import { Socket } from 'node:net';
|
|
3
3
|
import { Get, UniversalHandler, UniversalFn, Awaitable, UniversalMiddleware, RuntimeAdapterTarget, UniversalRouter, UniversalRouterInterface, EnhancedMiddleware } from '@universal-middleware/core';
|
|
4
4
|
import { Readable } from 'node:stream';
|
|
5
|
-
import { Express } from 'express';
|
|
5
|
+
import { Express as Express$2 } from 'express';
|
|
6
|
+
import { Express as Express$1 } from 'express4';
|
|
6
7
|
|
|
7
8
|
/** Adapter options */
|
|
8
9
|
interface NodeRequestAdapterOptions {
|
|
@@ -79,6 +80,7 @@ declare function getContext<InContext extends Universal.Context = Universal.Cont
|
|
|
79
80
|
*/
|
|
80
81
|
declare function sendResponse(fetchResponse: Response, nodeResponse: DecoratedServerResponse): Promise<void>;
|
|
81
82
|
|
|
83
|
+
type Express = Express$1 | Express$2;
|
|
82
84
|
type ConnectMiddleware = (req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) => void | Promise<void>;
|
|
83
85
|
type ConnectMiddlewareBoolean = (req: IncomingMessage, res: ServerResponse, next?: (err?: unknown) => void) => boolean | Promise<boolean>;
|
|
84
86
|
type WebHandler<InContext extends Universal.Context = Universal.Context, Target = unknown> = (request: Request, context?: InContext, runtime?: RuntimeAdapterTarget<Target>) => Response | undefined | Promise<Response | undefined>;
|
|
@@ -111,9 +113,9 @@ declare function createServerResponse(incomingMessage: IncomingMessage): {
|
|
|
111
113
|
}) => void) => void;
|
|
112
114
|
};
|
|
113
115
|
|
|
114
|
-
declare class UniversalExpressRouter extends UniversalRouter implements UniversalRouterInterface {
|
|
116
|
+
declare class UniversalExpressRouter<T extends Express> extends UniversalRouter implements UniversalRouterInterface {
|
|
115
117
|
#private;
|
|
116
|
-
constructor(app:
|
|
118
|
+
constructor(app: T);
|
|
117
119
|
use(middleware: EnhancedMiddleware): this;
|
|
118
120
|
applyCatchAll(): this;
|
|
119
121
|
}
|
package/dist/index.js
CHANGED
|
@@ -177,11 +177,15 @@ function overrideWriteHead(nodeResponse, callback) {
|
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function getFullUrl(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
180
|
+
function getFullUrl(pathnameOrFull, req) {
|
|
181
|
+
try {
|
|
182
|
+
return new URL(pathnameOrFull).href;
|
|
183
|
+
} catch {
|
|
184
|
+
const protocol = req.socket?.encrypted || req.headers["x-forwarded-proto"] === "https" ? "https" : "http";
|
|
185
|
+
const host = req.headers["x-forwarded-host"] || req.headers.host || "localhost";
|
|
186
|
+
const baseUrl = `${protocol}://${host}`;
|
|
187
|
+
return new URL(pathnameOrFull, baseUrl).href;
|
|
188
|
+
}
|
|
185
189
|
}
|
|
186
190
|
function responseAdapter(nodeResponse, bodyInit) {
|
|
187
191
|
if ([301, 302, 303, 307, 308].includes(nodeResponse.statusCode) && nodeResponse.req) {
|
|
@@ -510,6 +514,12 @@ function flattenHeaders(headers) {
|
|
|
510
514
|
}
|
|
511
515
|
return flatHeaders;
|
|
512
516
|
}
|
|
517
|
+
function isExpressV4(app) {
|
|
518
|
+
return "del" in app;
|
|
519
|
+
}
|
|
520
|
+
function isExpressV5(app) {
|
|
521
|
+
return !isExpressV4(app);
|
|
522
|
+
}
|
|
513
523
|
|
|
514
524
|
// src/router.ts
|
|
515
525
|
import {
|
|
@@ -529,7 +539,12 @@ var UniversalExpressRouter = class extends UniversalRouter {
|
|
|
529
539
|
return this;
|
|
530
540
|
}
|
|
531
541
|
applyCatchAll() {
|
|
532
|
-
|
|
542
|
+
if (isExpressV5(this.#app)) {
|
|
543
|
+
this.#app.all("/{*catchAll}", createHandler(() => this[universalSymbol2])());
|
|
544
|
+
}
|
|
545
|
+
if (isExpressV4(this.#app)) {
|
|
546
|
+
this.#app.all("/**", createHandler(() => this[universalSymbol2])());
|
|
547
|
+
}
|
|
533
548
|
return this;
|
|
534
549
|
}
|
|
535
550
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@universal-middleware/express",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Express adapter for universal middlewares",
|
|
6
6
|
"files": [
|
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@swc/core": "^1.11.13",
|
|
20
|
-
"@types/express": "^
|
|
20
|
+
"@types/express": "^5.0.1",
|
|
21
|
+
"@types/express4": "npm:@types/express@^4",
|
|
21
22
|
"@types/node": "^20.17.19",
|
|
22
|
-
"
|
|
23
|
+
"express4": "npm:express@^4",
|
|
24
|
+
"express": "^5.1.0",
|
|
23
25
|
"helmet": "^8.1.0",
|
|
24
26
|
"rimraf": "^6.0.1",
|
|
25
27
|
"tsup": "^8.4.0",
|