@fastify/reply-from
Advanced tools
Comparing version 9.0.1 to 9.0.2
@@ -20,2 +20,3 @@ 'use strict' | ||
ConnectionResetError, | ||
ConnectTimeoutError, | ||
UndiciSocketError, | ||
@@ -161,2 +162,4 @@ InternalServerError | ||
onError(this, { error: new UndiciSocketError() }) | ||
} else if (err.code === 'UND_ERR_CONNECT_TIMEOUT') { | ||
onError(this, { error: new ConnectTimeoutError() }) | ||
} else { | ||
@@ -163,0 +166,0 @@ onError(this, { error: new InternalServerError(err.message) }) |
@@ -12,3 +12,4 @@ 'use strict' | ||
module.exports.ConnectionResetError = createError('ECONNRESET', 'Connection Reset', 500) | ||
module.exports.ConnectTimeoutError = createError('UND_ERR_CONNECT_TIMEOUT', 'Connect Timeout Error', 500) | ||
module.exports.UndiciSocketError = createError('UND_ERR_SOCKET', 'Undici Socket Error', 500) | ||
module.exports.InternalServerError = createError('FST_REPLY_FROM_INTERNAL_SERVER_ERROR', '%s', 500) |
{ | ||
"name": "@fastify/reply-from", | ||
"version": "9.0.1", | ||
"version": "9.0.2", | ||
"description": "forward your HTTP request to another server, for fastify", | ||
@@ -35,3 +35,3 @@ "main": "index.js", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"@types/node": "^18.0.0", | ||
"@types/node": "^20.1.4", | ||
"@types/tap": "^15.0.7", | ||
@@ -50,3 +50,3 @@ "fastify": "^4.0.2", | ||
"tap": "^16.2.0", | ||
"tsd": "^0.26.0" | ||
"tsd": "^0.28.0" | ||
}, | ||
@@ -59,3 +59,3 @@ "dependencies": { | ||
"pump": "^3.0.0", | ||
"tiny-lru": "^10.0.0", | ||
"tiny-lru": "^11.0.0", | ||
"undici": "^5.19.1" | ||
@@ -62,0 +62,0 @@ }, |
@@ -315,2 +315,52 @@ # @fastify/reply-from | ||
Only http1! As http2 uses one connection for the whole session only the base upstream is used. If you want to | ||
have different upstreams based on the request you can add multiple Fastify.register's with different | ||
ContraintStrategies. | ||
e.g.: | ||
Route grpc-web/http1 and grpc/http2 to different routes with a ContentType-ConstraintStrategy: | ||
``` | ||
const contentTypeMatchContraintStrategy = { | ||
// strategy name for referencing in the route handler `constraints` options | ||
name: 'contentType', | ||
// storage factory for storing routes in the find-my-way route tree | ||
storage: function () { | ||
let handlers = {} | ||
return { | ||
get: (type: any) => { return handlers[type] || null }, | ||
set: (type: any, store: any) => { handlers[type] = store } | ||
} | ||
}, | ||
// function to get the value of the constraint from each incoming request | ||
deriveConstraint: (req: any, ctx: any) => { | ||
return req.headers['content-type'] | ||
}, | ||
// optional flag marking if handlers without constraints can match requests that have a value for this constraint | ||
mustMatchWhenDerived: true | ||
} | ||
server.addConstraintStrategy(contentTypeMatchContraintStrategy); | ||
``` | ||
and then 2 different upstreams with different register's: | ||
``` | ||
// grpc-web / http1 | ||
server.register(fastifyHttpProxy, { | ||
// Although most browsers send with http2, nodejs cannot handle this http2 request | ||
// therefore we have to transport to the grpc-web-proxy via http1 | ||
http2: false, | ||
upstream: 'http://grpc-web-proxy', | ||
constraints: { "contentType": "application/grpc-web+proto" } | ||
}); | ||
// grpc / http2 | ||
server.register(fastifyHttpProxy, { | ||
http2: true, | ||
upstream: 'http://grpc.server', | ||
constraints: { "contentType": "application/grpc+proto" } | ||
}); | ||
``` | ||
#### `queryString` or `queryString(search, reqUrl)` | ||
@@ -317,0 +367,0 @@ |
@@ -42,3 +42,6 @@ 'use strict' | ||
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => { | ||
get({ | ||
url: `http://localhost:${instance.server.address().port}`, | ||
agent: false | ||
}, (err, res, data) => { | ||
t.error(err) | ||
@@ -45,0 +48,0 @@ t.equal(res.headers['content-type'], 'text/plain') |
@@ -22,2 +22,3 @@ 'use strict' | ||
t.test('use a custom instance of \'undici\'', async t => { | ||
t.plan(3) | ||
t.teardown(target.close.bind(target)) | ||
@@ -28,3 +29,2 @@ | ||
t.test('disableRequestLogging is set to true', t => { | ||
t.plan(10) | ||
const logStream = split(JSON.parse) | ||
@@ -74,3 +74,2 @@ const instance = Fastify({ | ||
t.test('disableRequestLogging is set to false', t => { | ||
t.plan(8) | ||
const logStream = split(JSON.parse) | ||
@@ -120,3 +119,2 @@ const instance = Fastify({ | ||
t.test('disableRequestLogging is not defined', t => { | ||
t.plan(8) | ||
const logStream = split(JSON.parse) | ||
@@ -123,0 +121,0 @@ const instance = Fastify({ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
174403
103
5120
427
71
+ Addedtiny-lru@11.2.11(transitive)
- Removedtiny-lru@10.4.1(transitive)
Updatedtiny-lru@^11.0.0