Skip to content

Commit c8391c8

Browse files
committed
update uri schema for chat_channel connection to go based on .env url
1 parent d2e9660 commit c8391c8

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

app/channels/llama_bot_rails/chat_channel.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,20 @@ def setup_external_websocket(connection_id)
209209
end
210210

211211
uri = URI(websocket_url)
212-
213-
uri.scheme = 'wss'
214-
uri.scheme = 'ws' if Rails.env.development?
212+
213+
# Normalize the WebSocket URI scheme so it is always either ws:// or wss://.
214+
# We want to gracefully handle users passing in http/https URLs or omitting a scheme entirely.
215+
case uri.scheme&.downcase
216+
when 'wss', 'ws'
217+
# already valid, do nothing
218+
when 'https'
219+
uri.scheme = 'wss'
220+
when 'http'
221+
uri.scheme = 'ws'
222+
else
223+
# If a scheme is missing or unrecognized, fall back to sensible defaults
224+
uri.scheme = Rails.env.development? ? 'ws' : 'wss'
225+
end
215226

216227
endpoint = Async::HTTP::Endpoint.new(
217228
uri,

0 commit comments

Comments
 (0)