Skip to content

The target websocket watch the specific url instead of upstream(host) with path #303

@Dokki

Description

@Dokki

Prerequisites

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

🚀 Feature Proposal

Ability to customize the url for websockets, currently it is not possible.

Best regards, Anton.

Motivation

I use fastify-http-proxy for development, When I run project then the proxy is look at some server, for example: test, stage, feature.
Example:
I have server with backend api url like this https://api-test.myserver.com, and websocket url like this https://websocket.myserver.com/conection.
My local frontend looks at the proxy, and the proxy looks at backend api url. It working is well but when I turn on the websocket: true property then proxy trying to conect to wss://api-test.myserver.com and the url for sockets cannot be configured.
I ask to make it possible to configure the url for the websockets. Or can I suggest a solution with the pull request.

Example

Basically the solution is simple. Need add new property to proxy options, like wsUpstream.
This code

if (options.upstream !== '') {
    wsProxy.addUpstream(fastify.prefix, rewritePrefix, options.upstream, options.wsClientOptions)
    // The else block is validate earlier in the code
  }

Replace with

if (isDefinedString(options.wsUpstream) || isDefinedString(options.upstream)) {
    wsProxy.addUpstream(
      fastify.prefix,
      rewritePrefix,
      options.wsUpstream ? options.wsUpstream : options.upstream,
      options.wsClientOptions,
    )
    // The else block is validate earlier in the code
  }

Helper function

function isDefinedString (string) {
  return typeof string === 'string' && !!string
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions