Spring cloud gateway: Websockets on the same URL as HTTP(S)

Spring cloud gateway: Websockets on the same URL as HTTP(S)


1

I’m using Spring Cloud Gateway with a routing configuration like this:

spring:
  cloud:
    gateway:
      routes:
      - id: http
        uri: https://kubernetes-ingres-controller

In other words, I’m sending all paths onwards to somewhere else, which happens to be a K8s ingress controller. Spring adds some headers and handles the translation of session cookies into bearer tokens.

I’m starting to add some endpoints which handle websockets. However, since we are using websockets to do GraphQL subscriptions, we tend to have a single /graphql path which handles both ordinary GraphQL queries and websockets for subscriptions.

Is there a way to configure Spring Cloud Gateway to support both http and ws (or https and wss) on a single path?

I can do this:

spring:
  cloud:
    gateway:
      routes:
      - id: http
        uri: https://kubernetes-ingres-controller
      - id: ws
        uri: ws://kubernetes-ingres-controller
        predicates:
          - Path=/graphql

However it’s not clear to me that ordinary HTTP will work on the graphql path – and in practice there are many such paths; I’d prefer not to have to enumerate them all.

Some sort of setting to allow http with optional upgrade to wss on a single route would be ideal.


Load 3 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *