@nxtedition/lib 26.0.18 → 26.0.20
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/errors.js +3 -3
- package/http.js +8 -17
- package/package.json +1 -1
- package/serializers.js +11 -6
package/errors.js
CHANGED
|
@@ -30,10 +30,10 @@ export function parseError(error) {
|
|
|
30
30
|
fp.isEmpty(error.message) &&
|
|
31
31
|
fp.isEmpty(error.cause) &&
|
|
32
32
|
fp.isEmpty(error) &&
|
|
33
|
-
Array.isArray(
|
|
34
|
-
|
|
33
|
+
Array.isArray(error) &&
|
|
34
|
+
error.length === 1
|
|
35
35
|
) {
|
|
36
|
-
error =
|
|
36
|
+
error = error[0]
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const { msg, message = msg, errors, cause, data, ...properties } = error
|
package/http.js
CHANGED
|
@@ -74,14 +74,7 @@ export class Context {
|
|
|
74
74
|
if (this.#req.target) {
|
|
75
75
|
return this.#req.target
|
|
76
76
|
}
|
|
77
|
-
|
|
78
|
-
this.#target ??= Object.freeze(requestTarget(this.#req))
|
|
79
|
-
|
|
80
|
-
if (!this.#target) {
|
|
81
|
-
throw new createError.BadRequest('invalid url')
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return this.#target
|
|
77
|
+
return (this.#target ??= Object.freeze(requestTarget(this.#req)))
|
|
85
78
|
}
|
|
86
79
|
|
|
87
80
|
get query() {
|
|
@@ -205,7 +198,7 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
205
198
|
}
|
|
206
199
|
|
|
207
200
|
export async function requestMiddleware(ctx, next) {
|
|
208
|
-
const { req, res } = ctx
|
|
201
|
+
const { req, res, target } = ctx
|
|
209
202
|
const startTime = performance.now()
|
|
210
203
|
|
|
211
204
|
try {
|
|
@@ -214,6 +207,10 @@ export async function requestMiddleware(ctx, next) {
|
|
|
214
207
|
ctx.logger?.debug({ req }, 'request started')
|
|
215
208
|
}
|
|
216
209
|
|
|
210
|
+
if (!target) {
|
|
211
|
+
throw new createError.BadRequest('invalid url')
|
|
212
|
+
}
|
|
213
|
+
|
|
217
214
|
if (ctx.id) {
|
|
218
215
|
res.setHeader('request-id', ctx.id)
|
|
219
216
|
}
|
|
@@ -370,13 +367,7 @@ export class IncomingMessage extends http.IncomingMessage {
|
|
|
370
367
|
this.#target = undefined
|
|
371
368
|
}
|
|
372
369
|
|
|
373
|
-
this.#target ??= Object.freeze(requestTarget(this))
|
|
374
|
-
|
|
375
|
-
if (!this.#target) {
|
|
376
|
-
throw new createError.BadRequest('invalid url')
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return this.#target
|
|
370
|
+
return (this.#target ??= Object.freeze(requestTarget(this)))
|
|
380
371
|
}
|
|
381
372
|
|
|
382
373
|
get query() {
|
|
@@ -618,7 +609,7 @@ export class Http2ServerRequest extends http2.Http2ServerRequest {
|
|
|
618
609
|
this.#target = undefined
|
|
619
610
|
}
|
|
620
611
|
|
|
621
|
-
return (this.#target ??= requestTarget(this))
|
|
612
|
+
return (this.#target ??= Object.freeze(requestTarget(this)))
|
|
622
613
|
}
|
|
623
614
|
|
|
624
615
|
get query() {
|
package/package.json
CHANGED
package/serializers.js
CHANGED
|
@@ -83,12 +83,17 @@ function getTarget(obj) {
|
|
|
83
83
|
if (!obj) {
|
|
84
84
|
return undefined
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
if (obj.target) {
|
|
89
|
+
return obj.target
|
|
90
|
+
}
|
|
91
|
+
if (typeof obj.url === 'string') {
|
|
92
|
+
// TODO(fix): What if url is a full url?
|
|
93
|
+
return requestTarget({ url: obj.url, headers: obj.headers ?? {}, socket: obj.socket })
|
|
94
|
+
}
|
|
95
|
+
} catch {
|
|
96
|
+
return undefined
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
// TODO(fix): What if url is instanceof URL?
|