Skip to content

Allow for dynamic websocket upstreams with replyOptions.getUpstream #333

@jcbain

Description

@jcbain

Prerequisites

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

🚀 Feature Proposal

It would be nice to allow for dynamic upstreams when forwarding on websocket upgraded requests much in the same way that you can specify a getUpstream function to your replyOptions to pass some logic to determine an http upstream. However, leaving the wsUpstream property as an empty string results in the following error:

Error: upstream must be specified

It would be nice if this could be avoided when a getUpstream is supplied for an empty wsUpstream option.

Motivation

No response

Example

For example, it would be nice to register a websocket proxying mechanism like so

fastify.register(require('@fastify/http-proxy'), {
   websocket: true,
   wsUpstream: '',
   replyOptions: {
      getUpstream: function (req) {
          // some logic to determine the wsUpstream
      }
   }
})

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