@fastify/reply-from
Advanced tools
Comparing version 8.3.0 to 8.3.1
20
index.js
'use strict' | ||
const fp = require('fastify-plugin') | ||
const lru = require('tiny-lru') | ||
const { lru } = require('tiny-lru') | ||
const querystring = require('fast-querystring') | ||
@@ -24,3 +24,3 @@ const Stream = require('stream') | ||
module.exports = fp(function from (fastify, opts, next) { | ||
const fastifyReplyFrom = fp(function from (fastify, opts, next) { | ||
const contentTypesToEncode = new Set([ | ||
@@ -37,3 +37,3 @@ 'application/json', | ||
const base = opts.base | ||
const { request, close, retryOnError } = buildRequest({ | ||
const requestBuilt = buildRequest({ | ||
http: opts.http, | ||
@@ -44,2 +44,7 @@ http2: opts.http2, | ||
}) | ||
if (requestBuilt instanceof Error) { | ||
next(requestBuilt) | ||
return | ||
} | ||
const { request, close, retryOnError } = requestBuilt | ||
const disableRequestLogging = opts.disableRequestLogging || false | ||
@@ -66,4 +71,5 @@ | ||
if (cache) { | ||
url = cache.get(source) || buildURL(source, dest) | ||
cache.set(source, url) | ||
const cacheKey = dest + source | ||
url = cache.get(cacheKey) || buildURL(source, dest) | ||
cache.set(cacheKey, url) | ||
} else { | ||
@@ -281,1 +287,5 @@ url = buildURL(source, dest) | ||
} | ||
module.exports = fastifyReplyFrom | ||
module.exports.default = fastifyReplyFrom | ||
module.exports.fastifyReplyFrom = fastifyReplyFrom |
@@ -50,5 +50,5 @@ 'use strict' | ||
if (isHttp2) { | ||
if (!opts.base) throw new Error('Option base is required when http2 is true') | ||
if (!opts.base) return new Error('Option base is required when http2 is true') | ||
if (opts.base.startsWith('unix+')) { | ||
throw new Error('Unix socket destination is not supported when http2 is true') | ||
return new Error('Unix socket destination is not supported when http2 is true') | ||
} | ||
@@ -55,0 +55,0 @@ } else { |
{ | ||
"name": "@fastify/reply-from", | ||
"version": "8.3.0", | ||
"version": "8.3.1", | ||
"description": "forward your HTTP request to another server, for fastify", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
"@fastify/pre-commit": "^2.0.2", | ||
"@sinonjs/fake-timers": "^9.1.2", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"@types/node": "^18.0.0", | ||
@@ -50,3 +50,3 @@ "@types/tap": "^15.0.7", | ||
"tap": "^16.2.0", | ||
"tsd": "^0.23.0" | ||
"tsd": "^0.24.1" | ||
}, | ||
@@ -59,3 +59,3 @@ "dependencies": { | ||
"pump": "^3.0.0", | ||
"tiny-lru": "^8.0.2", | ||
"tiny-lru": "^10.0.0", | ||
"undici": "^5.5.1" | ||
@@ -62,0 +62,0 @@ }, |
@@ -206,4 +206,3 @@ # @fastify/reply-from | ||
[ | ||
'application/json', | ||
'application/x-www-form-urlencoded' | ||
'application/json' | ||
] | ||
@@ -210,0 +209,0 @@ ``` |
@@ -33,29 +33,2 @@ /// <reference types="node" /> | ||
import { Pool } from 'undici' | ||
type QueryStringFunction = (search: string | undefined, reqUrl: string) => string; | ||
export interface FastifyReplyFromHooks { | ||
queryString?: { [key: string]: unknown } | QueryStringFunction; | ||
contentType?: string; | ||
onResponse?: ( | ||
request: FastifyRequest<RequestGenericInterface, RawServerBase>, | ||
reply: FastifyReply<RawServerBase>, | ||
res: RawReplyDefaultExpression<RawServerBase> | ||
) => void; | ||
onError?: ( | ||
reply: FastifyReply<RawServerBase>, | ||
error: { error: Error } | ||
) => void; | ||
body?: unknown; | ||
rewriteHeaders?: ( | ||
headers: Http2IncomingHttpHeaders | IncomingHttpHeaders, | ||
req?: Http2ServerRequest | IncomingMessage | ||
) => Http2IncomingHttpHeaders | IncomingHttpHeaders; | ||
rewriteRequestHeaders?: ( | ||
req: Http2ServerRequest | IncomingMessage, | ||
headers: Http2IncomingHttpHeaders | IncomingHttpHeaders | ||
) => Http2IncomingHttpHeaders | IncomingHttpHeaders; | ||
getUpstream?: ( | ||
req: Http2ServerRequest | IncomingMessage, | ||
base: string | ||
) => string; | ||
} | ||
@@ -66,34 +39,69 @@ declare module "fastify" { | ||
source?: string, | ||
opts?: FastifyReplyFromHooks | ||
): void; | ||
opts?: fastifyReplyFrom.FastifyReplyFromHooks | ||
): this; | ||
} | ||
} | ||
interface Http2Options { | ||
sessionTimeout?: number; | ||
requestTimeout?: number; | ||
sessionOptions?: ClientSessionOptions | SecureClientSessionOptions; | ||
requestOptions?: ClientSessionRequestOptions; | ||
} | ||
type FastifyReplyFrom = FastifyPluginCallback<fastifyReplyFrom.FastifyReplyFromOptions> | ||
interface HttpOptions { | ||
agentOptions?: AgentOptions | SecureAgentOptions; | ||
requestOptions?: RequestOptions | SecureRequestOptions; | ||
agents?: { 'http:': Agent, 'https:': SecureAgent } | ||
} | ||
declare namespace fastifyReplyFrom { | ||
type QueryStringFunction = (search: string | undefined, reqUrl: string) => string; | ||
export interface FastifyReplyFromHooks { | ||
queryString?: { [key: string]: unknown } | QueryStringFunction; | ||
contentType?: string; | ||
onResponse?: ( | ||
request: FastifyRequest<RequestGenericInterface, RawServerBase>, | ||
reply: FastifyReply<RawServerBase>, | ||
res: RawReplyDefaultExpression<RawServerBase> | ||
) => void; | ||
onError?: ( | ||
reply: FastifyReply<RawServerBase>, | ||
error: { error: Error } | ||
) => void; | ||
body?: unknown; | ||
rewriteHeaders?: ( | ||
headers: Http2IncomingHttpHeaders | IncomingHttpHeaders, | ||
req?: Http2ServerRequest | IncomingMessage | ||
) => Http2IncomingHttpHeaders | IncomingHttpHeaders; | ||
rewriteRequestHeaders?: ( | ||
req: Http2ServerRequest | IncomingMessage, | ||
headers: Http2IncomingHttpHeaders | IncomingHttpHeaders | ||
) => Http2IncomingHttpHeaders | IncomingHttpHeaders; | ||
getUpstream?: ( | ||
req: Http2ServerRequest | IncomingMessage, | ||
base: string | ||
) => string; | ||
} | ||
export interface FastifyReplyFromOptions { | ||
base?: string; | ||
cacheURLs?: number; | ||
disableCache?: boolean; | ||
http?: HttpOptions; | ||
http2?: Http2Options | boolean; | ||
undici?: Pool.Options; | ||
contentTypesToEncode?: string[]; | ||
retryMethods?: (HTTPMethods | 'TRACE')[]; | ||
maxRetriesOn503?: number; | ||
disableRequestLogging?: boolean; | ||
interface Http2Options { | ||
sessionTimeout?: number; | ||
requestTimeout?: number; | ||
sessionOptions?: ClientSessionOptions | SecureClientSessionOptions; | ||
requestOptions?: ClientSessionRequestOptions; | ||
} | ||
interface HttpOptions { | ||
agentOptions?: AgentOptions | SecureAgentOptions; | ||
requestOptions?: RequestOptions | SecureRequestOptions; | ||
agents?: { 'http:': Agent, 'https:': SecureAgent } | ||
} | ||
export interface FastifyReplyFromOptions { | ||
base?: string; | ||
cacheURLs?: number; | ||
disableCache?: boolean; | ||
http?: HttpOptions; | ||
http2?: Http2Options | boolean; | ||
undici?: Pool.Options; | ||
contentTypesToEncode?: string[]; | ||
retryMethods?: (HTTPMethods | 'TRACE')[]; | ||
maxRetriesOn503?: number; | ||
disableRequestLogging?: boolean; | ||
} | ||
export const fastifyReplyFrom: FastifyReplyFrom | ||
export { fastifyReplyFrom as default } | ||
} | ||
declare const fastifyReplyFrom: FastifyPluginCallback<FastifyReplyFromOptions>; | ||
export default fastifyReplyFrom; | ||
declare function fastifyReplyFrom(...params: Parameters<FastifyReplyFrom>): ReturnType<FastifyReplyFrom> | ||
export = fastifyReplyFrom |
@@ -63,3 +63,3 @@ import replyFrom, { FastifyReplyFromOptions } from ".."; | ||
server.get("/v1", (request, reply) => { | ||
reply.from(); | ||
expectType<FastifyReply>(reply.from()); | ||
}); | ||
@@ -66,0 +66,0 @@ server.get("/v3", (request, reply) => { |
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
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
158660
95
4686
346
63
+ Addedtiny-lru@10.4.1(transitive)
- Removedtiny-lru@8.0.2(transitive)
Updatedtiny-lru@^10.0.0