fastify-http-proxy icon indicating copy to clipboard operation
fastify-http-proxy copied to clipboard

Allow for dynamic websocket upstreams with `replyOptions.getUpstream`

Open jcbain opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] 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
      }
   }
})

jcbain avatar Feb 06 '24 23:02 jcbain