Giter Site home page Giter Site logo

Comments (2)

Uzlopak avatar Uzlopak commented on June 16, 2024

It should be defined in FastifyReplyFromOptions but is missing there.

I am also wondering if it is implemented correct. I would expect that if i set options on registering the plugin than that they become the default settings for the actual reply.from call.

Current codebase is like this

const disableRequestLogging = opts.disableRequestLogging || false

  fastify.decorateReply('from', function (source, opts) {
    opts = opts || {}
    const req = this.request.raw
    const onResponse = opts.onResponse
    const rewriteHeaders = opts.rewriteHeaders || headersNoOp
    const rewriteRequestHeaders = opts.rewriteRequestHeaders || requestHeadersNoOp
    const getUpstream = opts.getUpstream || upstreamNoOp
    const onError = opts.onError || onErrorDefault
    const retriesCount = opts.retriesCount || 0
    const maxRetriesOn503 = opts.maxRetriesOn503 || 10

// And so on

I would have expected something like this:

const disableRequestLogging = opts.disableRequestLogging || false
const defaultOnResponse = opts.onResponse
const defaultRewriteHeaders = opts.onResonse || headersNoOp
const defaultGetUpstream = opts.getUpstream || upstreamNoOp
const defaultOnError = opts.onError || onErrorDefault
const defaultRetriesCount = opts.retriesCount || 0
const defaultMaxRetriesOn503 = opts.maxRetriesOn503 ?? 10

  fastify.decorateReply('from', function (source, opts) {
    opts || (opts = {})
    const req = this.request.raw
    const onResponse = opts.onResponse || defaultOnResponse
    const rewriteHeaders = opts.rewriteHeaders || defaultRewriteHeaders
    const rewriteRequestHeaders = opts.rewriteRequestHeaders || requestHeadersNoOp
    const getUpstream = opts.getUpstream || defaultGetUpstream
    const onError = opts.onError || defaultOnError
    const retriesCount = opts.retriesCount ?? defaultRetriesCount
    const maxRetriesOn503 = opts.maxRetriesOn503 ?? defaultMaxRetriesOn503

// And so on

In the current code you can not even set maxRetriesOn503 to 0 because of using || and not ??

I typed this comment with my phone so there can be typos in the code.

@mcollina
@climba03003

from fastify-reply-from.

mcollina avatar mcollina commented on June 16, 2024

if the implementation is not correct, I would love to see a test/repro to verify the problem.


@MaximeCheramy would you like to send a PR to add retriesCount to the types? I think it should go to the @fastify/reply-from module.

from fastify-reply-from.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.