Skip to content

reply.routeOptions is not available in decorators #5151

@PierBover

Description

@PierBover

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.23.2

Plugin version

No response

Node.js version

18

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

13.6

Description

According to the docs the reply object should have a routeOptions property. But when accessing the reply object outside a route handler this property doesn't exist.

I've hit this when trying to migrate away from reply.context.config in decorators after seeing the deprecation notice.

For reference and Google searches, the solution was to use the request object instead to access the route config using request.routeOptions.config.

I've looked at the decorator docs but didn't see any reference of this behavior.

Maybe I'm missing something... but if this is not the expected behavior I can provide a repro.

Steps to Reproduce

Try to access the reply.routeOptions from a decorator callback.

export default async function (request, reply) {
  console.log(reply.routeOptions); //returns undefined
}

Expected Behavior

According to the docs the reply object should have a routeOptions property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions