I have been trying to set up an action cable with ruby on rails version 7.0.4 and fail to do In the app/channels/application_cable.rb my configuration file is as below. As per official documentation, every connection should be identified, so I decided to identify that via random string:
module ApplicationCable class Connection < ActionCable::Connection::Base identified_by: random_string
def random_string
return SecureRandom.base64()
end
end end
I have only a single channel, called room_channel for learning purposes:
class RoomChannel < ApplicationCable::Channel
def subscribed stream_from "room_channel" end
def unsubscribed # Any cleanup needed when channel is unsubscribed end end
in the app/javascript/channels/consumer.js I created below configuration and set up at least 1 consumer, so my app could work
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
createConsumer(getWebSocketURL)
function getWebSocketURL() {
return "ws://159.61.241.9:8000/cable"
}
My config/environments/development.rb file is as below for action cable related settings:
config.action_cable.url = "ws://localhost:6379/cable"
config.action_cable.allowed_request_origins = ['http://159.65.241.9:8000']
config.action_cable.mount_path="ws://localhost:6379/cable"
my cable.yml file in the config as below:
development:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
test:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: action_cable_chat_app_production
I started up the redis server already. The error I end up with is as below:
Can someone please help me why WebSocket tries to start at 8000 port even though I mount the server in 6379 in the config file ?
Aucun commentaire:
Enregistrer un commentaire