jononomo
Websocket connection works on localhost, but get 403 error when deployed via docker
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error:
WebSocket connection to 'wss://web.my-app.convox/socket/websocket?userToken=726&vsn=1.0.0' failed: Error during WebSocket handshake: Unexpected response code: 403
I have also tried ws:// instead of wss:// and got the same result.
I used to have BasicAuth running in my app, but I have removed it.
My user_socket.ex file is as follows:
defmodule MyAppWeb.UserSocket do
use Phoenix.Socket
## Channels
channel "vw:*", MyAppWeb.VowpalWabbitChannel
## Transports
transport :websocket, Phoenix.Transports.WebSocket, check_origin: false
def connect(_params, socket) do
{:ok, socket}
end
def id(_socket) do
nil
end
end
What can i do to connect to my websocket in a non-dev environment?
Thanks.
Most Liked
baldmountain
@jononomo I just ran into this too. The way I fixed it is to use the check_origin option as suggested above, but instead of setting it false set it to a list of domains like
check_origin: ["//localhost", "//mycoolwebsite.com"]
where mycoolwebsite.com is the domain for your DigitalOcean Docker container.
matiso
From a security perspective, I would defintely not recommend disabling the origin check. It’s there for a reason, and disabling it to “just make it work” isn’t the right way to go.
IF your issue has to do with the origin, make sure to provide a whitelist of allowed origins, instead of completely disabling the check.
namosca
Hi, I was having this problem and your answer worked. I had to change it in user_socket.ex and prod.exs.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









