Convox Community

How to configure for Websockets?

We have an app with a Rails API backend and an accompanying chat server written in Node.js.

We have URLs like so:

Rails: https://stagingapi.arcadehub.co
Chat: https://staging-chat.arcadehub.co

The chat server runs a /health check on port 4000 and the socket.io server on port 5001.

In order for the /health check to work, we had to make the exposed port be 4000 for SSL.

It’s not at all clear how to expose port 5001 and associate it to the chat server domain name + SSL.

Current config is:

resources:
  redis:
    type: redis

balancers:
  chat:
    service: chat
    ports:
      5001: 5001
      4000: 4000

services:
  chat:
    image: 413704506032.dkr.ecr.us-east-2.amazonaws.com/arcade-chat:latest
    command: ./bin/www2
    health: /health
    environment:
      - "*"
    domain: ${CHAT_HOST}
    port: 4000
    ports:
      - 4000
      - 5001
    resources:
      - redis

  web:
    build: .
    command: bundle exec unicorn -c config/unicorn.rb
    health: /health
    port: 3000
    domain: ${HOST}
    environment:
      - "*"
    resources:
      - redis

Are there any example setups for this?

The only mention of websockets on convox I can find is an old blog post from 2016 that mentions ALB, and one unanswered query in the forums.

Should we be just using the endpoint url + port number to connect for now?

convox services -a arcade2-staging
SERVICE  DOMAIN                                              PORTS
chat     chat.arcade2-staging.d1e0ca97ed3e1743.convox.cloud   443:4000 5001
web      web.arcade2-staging.d1e0ca97ed3e1743.convox.cloud   443:3000

Alternatively, is there a way to configure the ALB so that it knows to pipe XHR traffic to port 5001?

Got it to work. The magic sauce was to add the - convox.port.443.protocol=tls configuration:

balancers:
  chat:
    service: chat
    ports:
      5001: 5001
      4000: 4000

services:
  chat:
    image: 413704506032.dkr.ecr.us-east-2.amazonaws.com/arcade-chat:latest
    command: ./bin/www2
    health: /health
    labels:
      - convox.port.443.protocol=tls

For anyone else encountering this, the above will only allow xhr comms. The secret sauce to get things fully working was to add convox.port.5001.protocol=wss. This ensures that incoming wss traffic are routed to port 5001.

services:
  chat:
    image: 413704506032.dkr.ecr.us-east-2.amazonaws.com/arcade-chat:latest
    command: ./bin/www2
    health: /health
    labels:
      - convox.port.443.protocol=tls
      - convox.port.5001.protocol=wss
    environment:
      - "*"
    domain: ${CHAT_HOST}
    scale:
      count: 1
    port: 4000
    ports:
      - 5001
    resources:
      - redis

I’ve since been told by Convox support that the above shouldn’t make any difference.

I’ll try and verify this.